java - How can I make a URLClassLoader behave like this? -


I'm trying to make a URLClassLoader that behaves as follows:

  • If
  • Otherwise, return a dummy class

I can not get it to work. In an effort given below, I hope test $ Thing to load special class loader successfully. In doing so, I hope this attempts to load the test $ supertying , and I hope the dummy class nothing is not loaded in place of it .

However, some> gets dashed and tossed a NoClassDefFoundError test for $ SuperThing

Does anybody know how to fix this? Public class test {Personal Stable Class SuperThing} Spreads Private Stable Class Talk SuperThing {} public static void (String [] args) {Set & lt; String & gt; Inclusions = New Hashet & lt; String & gt; (); Inclusions.add ("test $ talk"); // Note $ supershot is excluded URLClassLoader cl = (URLClassLoader) Thread.currentThread (). GetContextClassLoader (); Special Classloader Clove = New Specialty Classloader (CLLALS), inclusion); Try {Cll.loadClass ("Test $ Thing"); // line 22 (see Stacktrace below)} (ClasNotfound Expression E) {e.printStackTrace (); }} Private Static Class Nothing {} Private Static Final Class Special Class Lauder URL Class Loader {Private Final Set & lt; String & gt; Inclusion; Public Special ClassLoder (URL [] URL, set & lt; string & gt; inclusions) {super (url); The underlying = incorporation; } @ Override public class & lt ;? & Gt; Load class (string name) throws classless sound exposition {if (inclusions.contains (name)) {return findClass (name); // line 40 (see stacktrace below)} Return nothing. category; Edit}: Here I get the Stacktrace (Line numbers 22 and 40 are shown in the list above):

 Thread "Main" in Java Tests with the exception lang.NoClassDefFoundError: java.security.SecureClassLoader.defineClass (SecureClassLoader.java:124) on java.lang.ClassLoader.defineClass (ClassLoader.java:620) java.lang.ClassLoader.defineClass1 (Native method) at $ SuperThing on java.net.URLClassLoader.defineClass (URLClassLoader.java:260) in java.net.URLClassLoader.access $ 000 (URLClassLoader.java:56) java.net.URLClassLoader $ 1.run on (URLClassLoader.java:195 ) Test on java.security $ SpecialClassLoader.loadClass (Test.java:40) at .AccessController.doPrivileged (m L'Native Method) Test.main (Test.java:22) on java.net.URLClassLoader.findClass (URLClassLoader.java:188)   

what's happening here

  • when you try to load test $ Thing, defineClass law says that her test $ Thing is Need to load superclass; I.e. test $ superting

  • The system classloader calls your classloader, which does not provide anything.

  • System class loader says, "Oh, that class is not fully qualified classname !!", and throws NoClassDefFoundError .

Basically, this system classloader is protecting against things that will destabilize JVM. If this custom allows the classloader to load the wrong squares, then there can be dirty things. For example, think, what might happen if some code has applied some method defined for the test $ superting class, then after you cheat to classmoder to load the nang class.

If you have dirty tricks which are a dummy version of some class, you will need to generate a bytecode on the flight, using the correct perfect class name, correct superclass and interface, and with the correct signature Ways In essence, you have to fulfill binary compatibility rules. If you do not do this, the system classloader will refuse to load your class ... even then what you try to do in your custom classloader.

Frankly, you are trying to do whatever you are.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -