Hello I am trying to create a new instance of a class via reflection: In the example below the following applies: This is a method in a subclass of Arg1 Data is an object which stores class references which are associated with each other This code works when the provided arguments are from the same class loader, yet the code
Tag: classloader
Does the classloader load a class file if the corresponding class is never used?
To make my question more clear, consider following use-case: Suppose there is a package that permits a set of operations on a given platform, for example a class to edit the registry on Windows. This package does not exist on other platforms, as there is no equivalent operation on other operating system. For the sake of simplicity, consider windows/Registry.java and
Lambda expressions and anonymous classes don’t work when loaded as hidden classes
I am trying to compile and load dynamically generated Java code during runtime. Since both ClassLoader::defineClass and Unsafe::defineAnonymousClass have serious drawbacks in this scenario, I tried using hidden classes via Lookup::defineHiddenClass instead. This works fine for all classes that I tried to load, except for those that call lambda expressions or contain anonymous classes. Calling a lambda expression throws the
Why are log4j classes loaded by two class loaders?
I have a maven project for an application, which I run in a WildFly server. The project has log4j dependencies: I would like to get the LoggerContext like this: However, this results in ClassCastException: After some debugging, I have discovered that the problem is that the class LoggerContext is loaded via two different classloaders. How could this be possible? At
Java: Reading from getResourceAsStream gets too many bytes
I’m trying to read a binary file, using getResourceAsStream. The problem is I get too many bytes back. The file is 56374 bytes long, according to ls, but when I read it in my code, I consistently get 85194 bytes. I get the same result with similar code: If I run the code without the resource, everything is fine, I
Make a Java class visible from any ClassLoader
I’m using a Java Agent (Agent.class) to transform a method in a program (Program.class) in a way that includes a call to the Agent class. I’ve inspected the class loaders and their parents of both Agent and Program classes, and their hierarchy looks like this: Agent.class: AppClassLoader <- PlatformClassLoader <- null Program.class: URLClassLoader <- PlatformClassLoader <- null When the Program
Java config file multidimensional array
I have a problem. For my code I have a config file with the following content: To read this config file, I have the following code: But now I need to change the format of the names to: The output varialbe has to be of the type: String[][] with as result: What is the best way to achieve this? Answer
How to force AspectJ search from test directory in src directory of project using compile weaving?
Actually, it will be more complex question. I want use AspectJ only in test purpose. Have found suggestion to use if() JointPoint and some static boolean field. Also, first I start using aspect as inner static class of my base test method. After some experiments I replaced it to own class, but actually don’t got the result, that I want.
Reading resources inside dependency JAR gives NullPointerException
I have the following situation: JAR A has JAR B as dependency JAR B is packed with some resources that are loaded when JAR A calls specific methods of JAR B (loaded once and for all the lifecycle of JAR B calls) I am using Java SE 11 with IntelliJ 2021.1.3 JAR B resources tree is something like the following:
How do I give Drools access to dynamically loaded classes?
I am trying to use a ClassLoader to load classes from .class files at runtime and use them in Drools rules (Drools 7.52.0). I am using this custom ClassLoader which reads from a file and uses ClassLoader.defineClass() to load a class. It’s similar to a URLClassLoader: I can use the ClassLoader to load a class, construct an instance, and access