Java Class.isAssignableFull ALWAYS returns false ... only outside of the IDE

I tested on three Windows machines and two Linux VPS, on different versions of Java, both on OpenJDK and Oracle JDK. It worked perfectly, and then all of a sudden, it only works in my IDE, although I have not changed any relevant code, and I cannot imagine what might cause this.

Predefined code in the system:

Class<?> cls = (session == null ? secjlcl : session.getJLCL()).loadClass(name); Logger.log(JavaLoader.class.isAssignableFrom(cls) + " - " + cls + " - " + cls.getSuperclass().getName()); if (JavaLoader.class.isAssignableFrom(cls)) { 

And my ClassLoader:

 public class JavaLoaderClassLoader extends URLClassLoader { public JavaLoaderClassLoader(URL[] url, ClassLoader parent) { super(url); } private HashMap<String, Class<?>> javaLoaders = new HashMap<String, Class<?>>(); public String addClass(byte[] data) throws LinkageError { Class<?> cls = defineClass(null, data, 0, data.length); javaLoaders.put(cls.getName(), cls); return cls.getName(); } public Class<?> loadClass(String name, boolean resolve) { if (javaLoaders.containsKey(name)) return javaLoaders.get(name); try { Class<?> see = super.loadClass(name, resolve); if (see != null) return see; }catch (ClassNotFoundException e) { Logger.logError(e); } return null; } public void finalize() throws Throwable { super.finalize(); javaLoaders = null; } } 

One note, I expect many class loaders to load another file into the same name / package, so I use separate class loaders so that they are not split, however, when testing this was NOT tested.

Now it worked flawlessly in the past, and I don’t know why it stopped. I would suggest that I break something, but the code still works in my IDE?

+6
source share
1 answer

This seems to be your mistake:

 public JavaLoaderClassLoader(URL[] url, ClassLoader parent) { super(url); } 

You do not set parent as the loader of the parent class through the super constructor.

0
source

Source: https://habr.com/ru/post/985988/


All Articles