URL: <http://savannah.gnu.org/bugs/?func=detailitem&item_id=13251>
Summary: custom-made CharsetProvider cannot be loaded Project: classpath Submitted by: itokaz Submitted on: Wed 06/01/05 at 09:09 Category: classpath Severity: 3 - Normal Status: None Privacy: Public Assigned to: None Open/Closed: Open Platform Version: None _______________________________________________________ Details: 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 == '\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, + ClassLoader.getSystemClassLoader())).newInstance()); set.add(p); } } _______________________________________________________ Reply to this item at: <http://savannah.gnu.org/bugs/?func=detailitem&item_id=13251> _______________________________________________ Message sent via/by Savannah http://savannah.gnu.org/ _______________________________________________ Commit-classpath mailing list Commit-classpath@gnu.org http://lists.gnu.org/mailman/listinfo/commit-classpath