ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hans Lund <ha.l...@gmail.com>
Subject Classloading and CompilerAdapter problem
Date Wed, 08 Jul 2009 12:17:09 GMT
Hi All

I'm not sure if this is a bug, or just works as it should:

but when using ant to invoke the java runtime compiler
com.sun.tools.javac.Main this fails if ant is loaded from a parent
ClassLoader to tools.jar even though tools.jar is in the current context
classloader for the thread.


 
It fails in finding the compiler:->

>>From CompilerAdapterFactory:
----
 private static boolean doesModernCompilerExist() {
        try {
            Class.forName(MODERN_COMPILER);
            return true;
        } catch (ClassNotFoundException cnfe) {
            try {
                ClassLoader cl =
CompilerAdapterFactory.class.getClassLoader();
                if (cl != null) {
                    cl.loadClass(MODERN_COMPILER);
                    return true;
                }
            } catch (ClassNotFoundException cnfe2) {
                // Ignore Exception
            }
        }
        return false;
    }
 

, which is pretty much a nonsense implementation as 

     Class.forName('') is the same as
     CompilerAdapterFactory.class.getClassLoader().loadClass('') 

both will fail or both will succeed.



but why not use the Thread.currentThread.getContextClassLoader()
That would lead to the most flexible solution.
 
Regards
Hans Lund      


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message