printf in ClassLoader constructor causes java.lang.Error: java.lang.IllegalStateException: recursive invocation

Deepak Bhole dbhole at redhat.com
Wed Mar 23 10:42:08 PDT 2011


* Xerxes Rånby <xerxes at zafena.se> [2011-03-23 11:54]:
> Hi all, I am observing a spooky issue while working on a small classloader.
> In the classloader constructor, im able to use
> System.out.println
> while
> System.out.printf causes an exception
> 
> Is this an OpenJDK library bug or have I forgotten something crucial in my loader?
> 

Which version are you seeing this crash with? I am unable to reproduce
this with 1.9.7 or HEAD.

Deepak

> Testcase:
> 
> import java.io.File;
> 
> public class PrintfClassLoader extends ClassLoader {
> 
>     public PrintfClassLoader(ClassLoader parent) {
>         this(parent, defaultFiles());
>     }
> 
>     public PrintfClassLoader(ClassLoader parent, File[] files) {
>         super(parent);
>         System.out.println("Initializing Printf classloader....");
> 
>         // This  printf line are causing an exception... why???
>         System.out.printf("I am the Printf classloader!");
>     }
> 
>     @Override
>     protected Class<?> findClass(String name) throws ClassNotFoundException {
>         throw new ClassNotFoundException(name);
>     }
> 
>     private static File[] defaultFiles() {
>         return new File[0];
>     }
> }
> 
> 
> javac PrintfClassLoader.java
> java -Djava.system.class.loader=PrintfClassLoader
> Initializing Printf classloader....
> Error occurred during initialization of VM
> java.lang.Error: java.lang.IllegalStateException: recursive invocation
>     at java.lang.ClassLoader.initSystemClassLoader(ClassLoader.java:1323)
>     at java.lang.ClassLoader.getSystemClassLoader(ClassLoader.java:1286)
> Caused by: java.lang.IllegalStateException: recursive invocation
>     at java.lang.ClassLoader.initSystemClassLoader(ClassLoader.java:1303)
>     at java.lang.ClassLoader.getSystemClassLoader(ClassLoader.java:1286)
>     at java.util.ServiceLoader.loadInstalled(ServiceLoader.java:520)
>     at sun.util.LocaleServiceProviderPool$1.run(LocaleServiceProviderPool.java:118)
>     at java.security.AccessController.doPrivileged(Native Method)
>     at sun.util.LocaleServiceProviderPool.<init>(LocaleServiceProviderPool.java:116)
>     at sun.util.LocaleServiceProviderPool.getPool(LocaleServiceProviderPool.java:98)
>     at java.text.DecimalFormatSymbols.getInstance(DecimalFormatSymbols.java:147)
>     at java.util.Formatter.setZero(Formatter.java:2212)
>     at java.util.Formatter.init(Formatter.java:1838)
>     at java.util.Formatter.<init>(Formatter.java:1868)
>     at java.io.PrintStream.format(PrintStream.java:936)
>     at java.io.PrintStream.printf(PrintStream.java:838)
>     at PrintfClassLoader.<init>(PrintfClassLoader.java:14)
>     at PrintfClassLoader.<init>(PrintfClassLoader.java:6)
>     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
>     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
>     at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
>     at java.lang.SystemClassLoaderAction.run(ClassLoader.java:2016)
>     at java.security.AccessController.doPrivileged(Native Method)
>     at java.lang.ClassLoader.initSystemClassLoader(ClassLoader.java:1311)
>     at java.lang.ClassLoader.getSystemClassLoader(ClassLoader.java:1286)
> 
> Cheers
> Xerxes



More information about the distro-pkg-dev mailing list