I have some code that works just fine under the JDK but under
japhar it breaks badly. The error I get when I run it looks
like so. I was running on solaris but this same thing should
also happen under linux.
japhar --classpath share/classes.zip:jacl.jar tcl.lang.Shell
java/util/MissingResourceException (can't find resource for
java.text.resources.LocaleElements_en)
in
java/util/ResourceBundle.getBundle(Ljava/lang/String;Ljava/util/Locale;Ljava/lang/ClassLoader;)Ljava/util/ResourceBundle;(pc
= 141)
in
java/util/ResourceBundle.getBundle(Ljava/lang/String;Ljava/util/Locale;)Ljava/util/ResourceBundle;(pc
= 8)
in java/util/Calendar.setWeekCountData(Ljava/util/Locale;)V(pc = 21)
in java/util/Calendar.<init>(Ljava/util/TimeZone;Ljava/util/Locale;)V(pc = 53)
in java/util/GregorianCalendar.<init>(Ljava/util/TimeZone;Ljava/util/Locale;)V(pc =
6)
in java/util/GregorianCalendar.<init>()V(pc = 10)
in java/util/Date.<clinit>()V(pc = 13)
at tcl/lang/RandFunction.<clinit>()V(1688, pc = 3)
at tcl/lang/Expression.<init>()V(177, pc = 262)
at tcl/lang/Interp.<init>()V(312, pc = 47)
at tcl/lang/Shell.main([Ljava/lang/String;)V(51, pc = 9)
I did some more digging and got this detailed dump from japhar.
java frame: java/net/URL.<init> (pc = 270)
java frame: java/net/URL.<init> (pc = 6)
java frame: java/lang/ClassLoader.getSystemResource (pc = 13)
native frame: java/lang/ClassLoader.getSystemResourceAsStream0
java frame: java/lang/ClassLoader.getSystemResourceAsStream (pc = 4)
java frame: java/util/SystemClassLoader.getResourceAsStream (pc = 4)
java frame: java/util/ResourceBundle.findBundle (pc = 181)
java frame: java/util/ResourceBundle.getBundle (pc = 41)
java frame: java/util/ResourceBundle.getBundle (pc = 8)
java frame: java/util/Calendar.setWeekCountData (pc = 21)
java frame: java/util/Calendar.<init> (pc = 53)
java frame: java/util/GregorianCalendar.<init> (pc = 6)
java frame: java/util/GregorianCalendar.<init> (pc = 10)
java frame: java/util/Date.<clinit> (pc = 13)
java frame: tcl/lang/RandFunction.<clinit> (1688, pc = 3)
java frame: tcl/lang/Expression.<init> (177, pc = 262)
java frame: tcl/lang/Interp.<init> (312, pc = 47)
java frame: tcl/lang/Shell.main (51, pc = 9)
So it seemed like the problem was in the ClassLoader and how
it would call its native methods to resolve classes. So I
decided to look at the call stack both in the JDK and japhar
when the "system resources" were loaded. Here is what I found
out.
(running in sun jdk)
SystemClassLoader.loadClass() : now to
findSystemClass(java.text.resources.LocaleElements_en)
ClassLoader.findSystemClass() : now to
findSystemClass0(java.text.resources.LocaleElements_en)
ClassLoader.findSystemClass() : returning : class java.text.resources.LocaleElements_en
SystemClassLoader.loadClass() : returning : class java.text.resources.LocaleElements_en
SystemClassLoader.loadClass() : now to
findSystemClass(java.text.resources.LocaleElements)
ClassLoader.findSystemClass() : now to
findSystemClass0(java.text.resources.LocaleElements)
ClassLoader.findSystemClass() : returning : class java.text.resources.LocaleElements
SystemClassLoader.loadClass() : returning : class java.text.resources.LocaleElements
SystemClassLoader.loadClass() : now to
findSystemClass(java.text.resources.LocaleElements_en_US)
ClassLoader.findSystemClass() : now to
findSystemClass0(java.text.resources.LocaleElements_en_US)
SystemClassLoader.getResourceAsStream() : now to
ClassLoader.getSystemResourceAsStream(java/text/resources/LocaleElements_en_US.properties)
ClassLoader.getSystemResourceAsStream() : now to
getSystemResourceAsStream0(java/text/resources/LocaleElements_en_US.properties)
ClassLoader.getSystemResourceAsStream() : returning : null
SystemClassLoader.getResourceAsStream() : returning : null
(running in japhar)
SystemClassLoader.loadClass() : now to
findSystemClass(java.text.resources.LocaleElements_en)
ClassLoader.findSystemClass() : now to
findSystemClass0(java.text.resources.LocaleElements_en)
SystemClassLoader.getResourceAsStream() : now to
ClassLoader.getSystemResourceAsStream(java/text/resources/LocaleElements_en.properties)
ClassLoader.getSystemResourceAsStream() : now to
getSystemResourceAsStream0(java/text/resources/LocaleElements_en.properties)
ClassLoader.getSystemResource() : now to
getSystemResourceAsName0(java/text/resources/LocaleElements_en.properties)
ClassLoader.getSystemResource() : got resource named ""
ClassLoader.getSystemResource() : caught URL Exception
ClassLoader.getSystemResource() : returning : null
ClassLoader.getSystemResourceAsStream() : returning : null
SystemClassLoader.getResourceAsStream() : returning : null
SystemClassLoader.loadClass() : now to
findSystemClass(java.text.resources.LocaleElements_en)
ClassLoader.findSystemClass() : now to
findSystemClass0(java.text.resources.LocaleElements_en)
SystemClassLoader.getResourceAsStream() : now to
ClassLoader.getSystemResourceAsStream(java/text/resources/LocaleElements_en.properties)
ClassLoader.getSystemResourceAsStream() : now to
getSystemResourceAsStream0(java/text/resources/LocaleElements_en.properties)
ClassLoader.getSystemResource() : now to
getSystemResourceAsName0(java/text/resources/LocaleElements_en.properties)
ClassLoader.getSystemResource() : got resource named ""
ClassLoader.getSystemResource() : caught URL Exception
ClassLoader.getSystemResource() : returning : null
ClassLoader.getSystemResourceAsStream() : returning : null
SystemClassLoader.getResourceAsStream() : returning : null
SystemClassLoader.loadClass() : now to
findSystemClass(java.text.resources.LocaleElements)
ClassLoader.findSystemClass() : now to
findSystemClass0(java.text.resources.LocaleElements)
SystemClassLoader.getResourceAsStream() : now to
ClassLoader.getSystemResourceAsStream(java/text/resources/LocaleElements.properties)
ClassLoader.getSystemResourceAsStream() : now to
getSystemResourceAsStream0(java/text/resources/LocaleElements.properties)
ClassLoader.getSystemResource() : now to
getSystemResourceAsName0(java/text/resources/LocaleElements.properties)
ClassLoader.getSystemResource() : got resource named ""
ClassLoader.getSystemResource() : caught URL Exception
ClassLoader.getSystemResource() : returning : null
ClassLoader.getSystemResourceAsStream() : returning : null
SystemClassLoader.getResourceAsStream() : returning : null
java/util/MissingResourceException (can't find resource for
java.text.resources.LocaleElements_en)
at
java/util/ResourceBundle.getBundle(Ljava/lang/String;Ljava/util/Locale;Ljava/lang/ClassLoader;)Ljava/util/ResourceBundle;(340,
pc = 141)
at
java/util/ResourceBundle.getBundle(Ljava/lang/String;Ljava/util/Locale;)Ljava/util/ResourceBundle;(311,
pc = 8)
So it seems like the calling sequence is different when running
in japhar vs the JDK. This must be due to differences in the native
implementations of japhar and the JDK.
The first problem seems to be that the japhar implementation of
ClassLoader.findSystemClass0(String) is throwing and exception
instead of finding the resources that it should (resource in classses.zip).
It also seems like the "_US" part of the resource bundle is not getting
appended to the resource bundle name for the second resource search.
The java docs say the resources name should look like this.
baseclass + "_" + language + "_" + country
Is this a problem that you guys already know about? This seems like another
one of those JDK implementation issues that will not matter once
Japhar moves over to Classpath. Should I keep looking into it
or just put it off until Classpath arrives.
P.S.
If you want to try out the code I ran for this you can download it
here.
http://www.cs.umn.edu/~dejong/tcl/jacl.jar
Mo DeJong
dejong at cs.umn.edu