Hi,

I've checked in the attached patch to fix the fact that we're
incorrectly checking for the "charsetProvider" runtime permission when
instantiating the built in providers.

Regards,
Jeroen

2005-01-13  Jeroen Frijters  <[EMAIL PROTECTED]>

        * gnu/java/nio/charset/Provider.java: Added comment about its
        special relation with CharsetProvider.
        (static): Removed.
        * gnu/java/nio/charset/iconv/IconvProvider.java: Added comment
about
        its special relation with CharsetProvider.
        (static): Removed.
        * java/nio/charset/spi/CharsetProvider.java
        (CharsetProvider): Add special case to skip security check for
        built in providers.
Index: gnu/java/nio/charset/Provider.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/nio/charset/Provider.java,v
retrieving revision 1.7
diff -u -r1.7 Provider.java
--- gnu/java/nio/charset/Provider.java  22 Dec 2005 16:55:02 -0000      1.7
+++ gnu/java/nio/charset/Provider.java  13 Jan 2006 07:30:49 -0000
@@ -1,5 +1,5 @@
 /* Provider.java -- 
-   Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2005, 2006 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -49,6 +49,11 @@
  * Charset provider for the required charsets.  Used by
  * [EMAIL PROTECTED] Charset#charsetForName} and * [EMAIL PROTECTED] 
Charset#availableCharsets}.
  *
+ * Note: This class is a privileged class, because it can be instantiated 
without
+ * requiring the RuntimePermission("charsetProvider"). There is a check in
+ * java.nio.charset.spi.CharsetProvider to skip the security check if the 
provider
+ * is an instance of this class.
+ *
  * @author Jesse Rosenstock
  * @author Robert Schuster ([EMAIL PROTECTED])
  * @see Charset
@@ -57,14 +62,6 @@
 {
   private static Provider singleton;
 
-  static
-  {
-    synchronized (Provider.class)
-      {
-        singleton = null;
-      }
-  }
-
   /**
    * Map from charset name to charset canonical name. The strings
    * are all lower-case to allow case-insensitive retrieval of
Index: gnu/java/nio/charset/iconv/IconvProvider.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/nio/charset/iconv/IconvProvider.java,v
retrieving revision 1.3
diff -u -r1.3 IconvProvider.java
--- gnu/java/nio/charset/iconv/IconvProvider.java       7 Nov 2005 22:08:33 
-0000       1.3
+++ gnu/java/nio/charset/iconv/IconvProvider.java       13 Jan 2006 07:30:46 
-0000
@@ -1,5 +1,5 @@
 /* IconvProvider.java --
-   Copyright (C) 2005 Free Software Foundation, Inc.
+   Copyright (C) 2005, 2006 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -48,20 +48,17 @@
 /**
  * Charset provider wrapping iconv.
  *
+ * Note: This class is a privileged class, because it can be instantiated 
without
+ * requiring the RuntimePermission("charsetProvider"). There is a check in
+ * java.nio.charset.spi.CharsetProvider to skip the security check if the 
provider
+ * is an instance of this class.
+ *
  * @author Sven de Marothy
  */
 public final class IconvProvider extends CharsetProvider
 {
   private static IconvProvider singleton;
 
-  static
-    {
-      synchronized (IconvProvider.class)
-        {
-         singleton = null;
-        }
-    }
-
   // Declaring the construtor public may violate the use of singleton.
   // But it must be public so that an instance of this class can be
   // created by Class.newInstance(), which is the case when this provider is
Index: java/nio/charset/spi/CharsetProvider.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/java/nio/charset/spi/CharsetProvider.java,v
retrieving revision 1.4
diff -u -r1.4 CharsetProvider.java
--- java/nio/charset/spi/CharsetProvider.java   2 Jul 2005 20:32:40 -0000       
1.4
+++ java/nio/charset/spi/CharsetProvider.java   13 Jan 2006 07:30:44 -0000
@@ -1,5 +1,5 @@
 /* CharsetProvider.java -- charset service provider interface
-   Copyright (C) 2002 Free Software Foundation
+   Copyright (C) 2002, 2006 Free Software Foundation
 
 This file is part of GNU Classpath.
 
@@ -67,8 +67,12 @@
    */
   protected CharsetProvider()
   {
+    // We only do the security check for custom providers, not for the
+    // built in ones.
     SecurityManager s = System.getSecurityManager();
-    if (s != null)
+    if (s != null &&
+        ! (this instanceof gnu.java.nio.charset.Provider
+        || this instanceof gnu.java.nio.charset.iconv.IconvProvider))
       s.checkPermission(new RuntimePermission("charsetProvider"));
   }
 
_______________________________________________
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to