bug-classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-classpath] [Bug classpath/22963] New: custom-made CharsetProvider c


From: pinskia at gcc dot gnu dot org
Subject: [bug-classpath] [Bug classpath/22963] New: custom-made CharsetProvider cannot be loaded
Date: 26 Jul 2005 16:02:46 -0000

I have a custom-made class that extends

   java.nio.charset.spi.CharsetProvider

whose name is written in

   META-INF/services/java.nio.charset.spi.CharsetProvider.



I have found two problems when the VM loads the custom-made

CharsetProvider.



(1) We can put blank lines, spaces, tabs and comments following

    '#' in META-INF/services/java.nio.charset.spi.CharsetProvider.

    But java.nio.charset.Charset does not ignore them.



(2) java.nio.charset.Charset tries to load the class using

    Class.forName(className), which means that the ClassLoader

    that loaded java.nio.charset.Charset is used.  Most likely,

    java.nio.charset.Charset is in the VM's bootstrap classpath,

    so the custom-made CharsetProvider must also be found somewhere

    in the VM's bootstrap classpath.  Just putting it in the

    usual classpath does not work.



And here is my proposed patch:



--- java/nio/charset/Charset.java.orig  Wed Jun  1 16:56:01 2005

+++ java/nio/charset/Charset.java       Wed Jun  1 17:28:43 2005

@@ -267,8 +267,29 @@

                     String s = rdr.readLine();

                     if (s == null)

                      break;

+                   int i = -1, j = -1;

+                   for (int k = 0; k < s.length(); k++)

+                     {

+                       char c = s.charAt(k);

+                       if (c == ' ' || c == '  ')

+                         continue;

+                       if (c == '#')

+                         break;

+                       i = k;

+                       break;

+                     }

+                   if (i < 0)

+                       continue;

+                   for (j = i + 1; j < s.length(); j++)

+                     {

+                       char c = s.charAt(j);

+                       if (c == ' ' || c == '  ' || c == '#')

+                         break;

+                     }

+                   s = s.substring(i, j); 

                     CharsetProvider p =

-                     (CharsetProvider) ((Class.forName(s)).newInstance());

+                     (CharsetProvider) ((Class.forName(s, true,

+                        ClassLoader.getSystemClassLoader())).newInstance());

                     set.add(p);

                   }

                }


------- Additional Comments From from-classpath at savannah dot gnu dot org  
2005-06-01 23:16 -------
> + (CharsetProvider) ((Class.forName(s, true,

> + ClassLoader.getSystemClassLoader())).newInstance());



This must be Thread.currentThread().getContextClassLoader()

instead of ClassLoader.getSystemClassLoader().




------- Additional Comments From from-classpath at savannah dot gnu dot org  
2005-06-05 22:25 -------
This is the patch applied in Kaffe.



ChangeLog:



2005-06-05  Ito Kazumitsu  <address@hidden>



        * java/nio/charset/Charset.java

        (providers2): Allow spaces and comments in

        META-INF/services/java.nio.charset.spi.CharsetProvider.

        Load the provider using the context class loader.



--- java/nio/charset/Charset.java.orig  Wed May 18 06:28:40 2005

+++ java/nio/charset/Charset.java       Sun Jun  5 10:52:25 2005

@@ -267,8 +267,29 @@

                     String s = rdr.readLine();

                     if (s == null)

                      break;

+                   int i = -1, j = -1;

+                   for (int k = 0; k < s.length(); k++)

+                     {

+                       char c = s.charAt(k);

+                       if (c == ' ' || c == '\t')

+                         continue;

+                       if (c == '#')

+                         break;

+                       i = k;

+                       break;

+                     }

+                   if (i < 0)

+                       continue;

+                   for (j = i + 1; j < s.length(); j++)

+                     {

+                       char c = s.charAt(j);

+                       if (c == ' ' || c == '\t' || c == '#')

+                         break;

+                     }

+                   s = s.substring(i, j);

                     CharsetProvider p =

-                     (CharsetProvider) ((Class.forName(s)).newInstance());

+                     (CharsetProvider) ((Class.forName(s, true,

+                        
Thread.currentThread().getContextClassLoader())).newInstance());

                     set.add(p);

                   }

                }




------- Additional Comments From from-classpath at savannah dot gnu dot org  
2005-06-06 00:29 -------
Thanks, I'll check this into Classpath.
------- Additional Comments From pinskia at gcc dot gnu dot org  2005-07-26 
16:02 -------
Confirmed.

-- 
           Summary: custom-made CharsetProvider cannot be loaded
           Product: classpath
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P3
         Component: classpath
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: from-classpath at savannah dot gnu dot org
                CC: bug-classpath at gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22963




reply via email to

[Prev in Thread] Current Thread [Next in Thread]