classloader

ClassCircularityError thrown by ClassLoader.defineClass

非 Y 不嫁゛ 提交于 2020-01-02 00:58:09
问题 I'm loading classes using a custom class loader. For the most part, everything works, but sometimes when I load particularly complex projects/libraries, I get a strange bug: Exception in thread "main" java.lang.ClassCircularityError: org/apache/commons/codec/binary/Hex at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632) at java.lang.ClassLoader.defineClass(ClassLoader.java:616) at java.lang.ClassLoader.defineClass(ClassLoader

Custom class loading/overriding Android-native classes

放肆的年华 提交于 2020-01-01 09:05:16
问题 Main goal is to override Android system class (Activity, View etc) with my own implementation. http://android-developers.blogspot.com/2011/07/custom-class-loading-in-dalvik.html ClassLoader for custom class loading is implemented, loading non-system class (custom class) works. But when I try to load Activity with my implementation - it doesn't load, because ClassLoader already has this class in its cache: /** * Returns the class with the specified name if it has already been loaded * by the

Declaring variable final and static

好久不见. 提交于 2020-01-01 07:53:50
问题 This comment was made in a code review and the person who made it is no longer on our team. Any type that must be resolved by the classloader at runtime should never have instances which are held by references declared to be both final and static. Here's the line of code: private final static Logger log = LoggerFactory.getLogger(MyClass.class); I'm familiar with the debate of declaring loggers static or non-static, but this comment seems to be more general. I can't find any explanations of

Declaring variable final and static

て烟熏妆下的殇ゞ 提交于 2020-01-01 07:53:46
问题 This comment was made in a code review and the person who made it is no longer on our team. Any type that must be resolved by the classloader at runtime should never have instances which are held by references declared to be both final and static. Here's the line of code: private final static Logger log = LoggerFactory.getLogger(MyClass.class); I'm familiar with the debate of declaring loggers static or non-static, but this comment seems to be more general. I can't find any explanations of

How do I get a list of packages and/or classes on the classpath?

帅比萌擦擦* 提交于 2020-01-01 06:54:07
问题 In Java, I can use a ClassLoader to get a list of classes that are already loaded, and the packages of those classes. But how do I get a list of classes that could be loaded, i.e. are on the classpath? Same with packages. This is for a compiler; when parsing foo.bar.Baz, I want to know whether foo is a package to distinguish it from anything else. 回答1: Its a bit tricky and there are a few libraries that can help, but basically... Look at your classpath If you are dealing with a directory, you

How does a classloader load classes reference in the manifest classpath?

冷暖自知 提交于 2020-01-01 04:46:24
问题 I used maven to built a jar with an external classpath additions using addClasspath. When I run that jar using java -jar artifact.jar it is able to load classes from that main jar and from all jars in the libs directory. However if I ask the system property java.class.path it will only list the main jar. If I ask the system class loader for its urls ( ClassLoader.getSystemClassLoader().getURLs() ) it will also only return the main jar. If I ask any class contained in some library for its

Javassist: re-creating a class - delete first, or defrost() and modify?

∥☆過路亽.° 提交于 2020-01-01 03:24:07
问题 I use Javassist to create a class. And in a test suite, when a second test tries to create the same class, it fails at pool.makeClass( ... ) because the class is frozen (i.e. already created via toClass() . What's the way to overcome this? Ideally, the first test should delete the class somehow - perhaps unload from the classloader - but as I read in JLS, the unload operation is not reliable. So perhaps the workaround is to check in the class creating code whether it exists, and if it does,

Java ASM Bytecode Modification-Changing method bodies

六眼飞鱼酱① 提交于 2019-12-31 22:21:11
问题 I have a method of a class in a jar whose body I want to exchange with my own. In this case I just want to have the method print out "GOT IT" to the console and return true; I am using the system loader to load the classes of the jar. I am using reflection to make the system classloader be able to load classes by bytecode. This part seems to be working correctly. I am following the method replacement example found here: asm.ow2.org/current/asm-transformations.pdf. My code is as follows:

How does clojure class reloading work?

爷,独闯天下 提交于 2019-12-31 08:12:53
问题 I've been reading code and documentation to try to understand how class reloading works in clojure. According to many websites, such as http://tutorials.jenkov.com/java-reflection/dynamic-class-loading-reloading.html , whenever you load a class essentially you obtain the bytecode (via any data mechanism), convert the bytecode into an instance of class Class (via defineClass), and then resolve (link) the class via resolveClass. (Does defineClass implicitly call resolveClass?). Any given

How do intern'd strings behave between different threads and classloarders?

大憨熊 提交于 2019-12-31 05:19:09
问题 In java's documentation it says that in the below example, the condition will be true: String a = new String("ABC"); String b = new String("ABC"); if (a.intern() == b.intern()) { .... } I wanted to know, if that is still true when considering that a and b are defined in different Threads , or even different ClassLoaders ? This question rose when I needed an ability to synchronize a block that loads a certain configuration based on an entity's name, so I wanted to do something like: