Questions tagged [classloader]

A class loader is an object that is responsible for loading classes in Java.

Filter by
Sorted by
Tagged with
0 votes
0 answers
20 views

Flink. Class loading leak in the JobManager

Flink 1.15.4 After every executed job for an uploaded jar, the metaspace on the job manager keeps increasing, because a class loader can't be GC-ed. Initially, I suspected that it's due to the org....
Konstantin's user avatar
0 votes
0 answers
33 views

Why does unit testcase run before the init block in companion object?

I have three enum class with init block in companion object. All of them have the same method like XXX.register() @Test fun aTest(){ val objectMapper = ObjectMapper() val readValue: InterfaceA ...
wl.GIG's user avatar
  • 306
-3 votes
0 answers
35 views

Weird behavior: ClassCastException always thrown except when converting object to JSON string and converting it back to its class

I'm currently working on a task that consists of creating a REST Api that retrieves some data, maps it (extract only the needed values) and returns it as a response. This is the flow: Controller -> ...
artificialdeathinthewest's user avatar
1 vote
0 answers
71 views

Dynamically load jars using classloader in Java 17(migrating from Java 8 to Java 17)

I have classsloading code which is working fine in Java 8(it's a bit old code). Now we are trying to migrate from Java 8 to Java 17. While migrating to Java 17, we got an error which loads JARs at ...
SudeepShakya's user avatar
0 votes
0 answers
55 views

Java Classloaders types

As mentioned in JVM specification: There are two kinds of class loaders: the bootstrap class loader supplied by the Java Virtual Machine, and user-defined class loaders. Every user-defined class ...
gaurs's user avatar
  • 583
0 votes
0 answers
49 views

Cannot instantiate class: "com.sun.jndi.ldap.LdapCtxFactory" since moved from jdk8 to jdk11

I have a Spring Boot (v2.4.5) web application that is using (in one of the Service classes) an LDAP search if user detail data. This search worked while we were using JDK8 but once we transitioned to ...
Csaba Csenteri's user avatar
0 votes
1 answer
32 views

Class loaded with ClassLoader but fails when instantiated due to referenced class

I'm loading a class from an external jar like this: private Class<?> loadClassFromJar(File jarFile, String className) throws IOException, ClassNotFoundException { URL jarUrl = jarFile....
misty's user avatar
  • 123
-1 votes
0 answers
38 views

How to register a custom ClassLoader with ServiceLoader for a JUnit Launcher?

I would like to use a custom ClassLoader when programmatically running JUnit tests. According to the JUnit 5 User Guide: In order to intercept the creation of instances of Launcher and ...
Ellen Spertus's user avatar
4 votes
1 answer
68 views

Modify embedded Apache James Classloader to allow for custom hooks in same project

I am attempting to run my own custom in-memory James assembly inside of a Quarkus web application. I've been following along with the example here and gotten the server to run. One of the issues I'm ...
TheFunk's user avatar
  • 981
0 votes
1 answer
46 views

aspecj-maven-plugin, weaving dependency feature, random load java class

I use maven-aspectj-plugin in a multi modules project using maven as a dependency tool. A simple demo project, you could find here demo-project. At my real project, for the compatibiliy with lombok, I ...
Chuang Hou's user avatar
1 vote
0 answers
85 views

EAR application deployment on Wildfly 22 fails to find javax.servlet.Filter

I'm trying to deploy an EAR application to WildFly Preview 22.0.1.Final. I'm aware that JBoss/WildFly class loading is different from e.g. WAS, so I went through docs but I'm still not sure if I ...
peterremec's user avatar
0 votes
0 answers
28 views

How to create a transforming class loader

I am trying to make a class loader which transforms the class bytes of the class being loaded using some kind of class transformer. Suppose I have the following code: static class Test { void foo(); ...
asdafadsfadsfdaf's user avatar
1 vote
0 answers
13 views

How to load a subdirectory inside resources folder using -Dloader.path?

The folder created inside jar is BOOT-INF/classes/global/DEV. Now I'm running the application with below command which is not loading the properties files inside DEV folder. java -Dloader.path=/BOOT-...
Subhrajyoti Shaseni's user avatar
0 votes
0 answers
81 views

Quarkus native build problem: No NameResolverProviders found via ServiceLoader

I have a well tested Quarkus microservice that I am trying to build in native mode. I am using latest Quarkus 3.2.2.Final. Problem is not present in JVM mode. When I start the native microservice, ...
stuhpa's user avatar
  • 306
5 votes
1 answer
261 views

Which exact classes are loaded by Platform ClassLoader?

Let's assume, we're using OpenJDK 20. The official documentation says: The platform class loader is responsible for loading the platform classes. Platform classes include Java SE platform APIs, their ...
Yahor Barkouski's user avatar
0 votes
0 answers
21 views

How does static block works across different classes in java? [duplicate]

class Details { static private int age; static { age=45; System.out.println("Static block."); } private String name; { name="Satyam"; ...
Satyam Mishra's user avatar
0 votes
0 answers
84 views

Java ClassLoader: Get static field declared in a JAR 1. JAR1 used by another JAR 2

I want to extract static field from another program. That program is launched through java reflection and URLClassLoader: private static final String ProgramClassName = "com.myproject.MyMainClass&...
Igor Adamovich's user avatar
0 votes
0 answers
24 views

Apache Flink cast exception when deployed to AWS Kinesis Data Analytics

We are prototyping Flink to do some basic analytics. We are consuming from 2 Kinesis streams inside the same Job when deployed. When I run locally using custom sources to generate data, everything ...
6footunder's user avatar
  • 1,318
1 vote
0 answers
51 views

Java classcasting / classloading mess in SAP CPI

I'm working on a Groovy script in the SAP CPI environment which means the script runs in a somewhat canned JVM. I uploaded the jjwt-api-0.11.2, jjwt-impl-0.11.2 and jjwt-jackson-0.11.2 jars, in order ...
Vladimir's user avatar
  • 393
0 votes
0 answers
17 views

Failed to load decrypted class from custom classloader spring boot

I am creating a spring-boot application which is trying to encrypt the class files on compile and decrypt them during start-up. I have encrypted the files and added in to the JAR. To achieve the ...
Chathura Dissanayake's user avatar
0 votes
0 answers
35 views

How to reload class in spring boot classloader?

There is situation where I need to update class binaries without restarting spring boot application. I know there are ways for creating a new class Loader each time when new binaries are required to ...
Arpan's user avatar
  • 9
1 vote
1 answer
43 views

Application JAXB namespace mapper custom implementation not working in Liberty

I'm migrating from WAS to Liberty where in we are having JAXB as application dependency. I have extended the NamespaceMapper of the jaxb-impl and when I'm trying to set it to Marshaller Property I'm ...
Igupta's user avatar
  • 31
-1 votes
1 answer
61 views

How do I solve this LinkageError duplicate class definition?

I'm using IcedTea-Web to run a java application with jnlp/javaws. The application used to work fine running with Java 8 and java web start. I'm trying to move to Java 17 and IcedTea-Web. The error I ...
Sybuser's user avatar
  • 735
1 vote
0 answers
17 views

How can I load a service provider from a module layer with a custom class loader?

I am trying to load a service provider from my own module layer, using a custom class loader. I am receiving the error: Exception in thread "main" java.util.ServiceConfigurationError: client....
JasonBourne's user avatar
0 votes
0 answers
26 views

Reading file from src/test/resources

I want to test a method, which should return lines from the file src/test/resources using getClassLoader::getResourceAsStream(). When I run the test I get NPE. public class ResourceReader { ...
Berder's user avatar
  • 1
1 vote
1 answer
86 views

is Java ServiceLoader using the System Class Loader, or the Platform/Extension Class Loader?

Java JDK ServiceLoader as some complex information, and I have a hard time getting this one thing straight: Which class loader it uses. This question concerns the range of JDKs from JDK8 to JDK17. ...
foo's user avatar
  • 1,968
0 votes
0 answers
62 views

How can I assign a custom classloader to a module layer in Java?

Following the wake of JEP 411, I am trying to create a simple sandbox in Java for loading untrusted code. Unfortunately, I am unfamiliar with the module system and it seems I cannot get my created ...
JasonBourne's user avatar
2 votes
2 answers
527 views

Classes used in method body are loaded lazily or eagerly depending on method return type

I'm making an API wrapper library that supports multiple versions of the API. A public class was added in the recent API version. I'm trying to compile the wrapper against the latest API version and ...
basin's user avatar
  • 3,978
3 votes
2 answers
134 views

Error when trying to use dynamically loaded libraries

I'm trying to dynamically load libraries instead of shading them into my JAR to reduce file size. It's a standalone application with a Bootstrap class and a Main class. The main class is responsible ...
asdafadsfadsfdaf's user avatar
0 votes
0 answers
26 views

declare a variable with interface type and initialize with concrete type, when will the concrete class will be loaded

here is the sample code: @RestController @RequestMapping("/v1/user") public class JsonSampleController { @GetMapping public User getUser() { Vehicle vehicle = new Car(); ...
nzomkxia's user avatar
  • 1,219
5 votes
1 answer
183 views

Why main thread not wake up?

The code is below, in the Main method I call a static method: public class Main { public static void main(String[] args) { MyFactory.getSomething(); System.out.println("over&...
Q10Viking's user avatar
  • 1,002
0 votes
0 answers
34 views

Forbid external lib's class methods to access network in Java 8

I have application which uses external library for parsing some files and I want to prevent external lib's classes from sending any http requests. Can it be achieved without using SecurityManager? I ...
Denec's user avatar
  • 1
0 votes
1 answer
72 views

What happened when use `classloader.close`?

I found that the reason is I use classloader.close(). This is the erroe code. error: java.lang.NoClassDefFoundError: org/postgresql/Driver$1 try (URLClassLoader classLoader = URLClassLoader....
Cpeony's user avatar
  • 3
1 vote
1 answer
145 views

How to include custom ClassLoader coverage in EclEmma reports?

I have a number of classes that statically initialize constants based on system arch properties. To fully test them, I have used a custom class loader to reload the classes from files after changing ...
boot-and-bonnet's user avatar
2 votes
2 answers
73 views

java memory management -java class loader

I am a beginner in java,for understanding java memory management i was reading book 'Java Memory Management By Maaike van Putten , Seán Kennedy ' I encountered this statement "To be able to ...
opreddy's user avatar
  • 21
0 votes
1 answer
240 views

How can I implement a custom class loader in Java that dynamically loads and executes Java code at runtime?

I am building a Java-based application that needs to dynamically load and execute plugin classes at runtime. Each plugin is represented by a separate Java class file that implements a common interface ...
user avatar
0 votes
1 answer
317 views

Java ClassLoader loading class only for its own context?

I have some strange edge case behavior I want to discuss and solve with you. And as a heads-up: Please do not ask why I want to do something :) As far as my understanding goes, the JVM loads classes ...
micartey's user avatar
  • 128
0 votes
1 answer
129 views

Reading classes from System Class Loader returns empty array

I have a very simple program that attempts to read class files under a given package. This works fine locally (JDK 11) but when I run it on a Red Hat Linux 8 server (JDK 11), the same exact code ...
alessandro ferrucci's user avatar
0 votes
0 answers
165 views

WAR classes and libraries of an EAR are not getting loaded by classloader for Websphere Liberty

An EAR file is deployed successfuly on Websphere Traditional (For both 8.5.5 and 9.0) and having below structure: EApplication.ear |--> META-INF |-->application....
Technogix's user avatar
0 votes
1 answer
59 views

Reading resources from eclipse and a runable jar

I'm trying to read files in a directory from the runnable jar, but the follwing code works only in eclipse, however, it doesnt work in the running jar using java command import java.io.File; import ...
ibrahim 's user avatar
0 votes
0 answers
52 views

What's the proper way to isolate plugins loaded via `ServiceLoader`?

I'm using Java's ServiceLoader to load plugins into my app. The plugins are provided as JARs on the classpath when starting the app. Now, if these plugins contain classes or resources with the same ...
sschuberth's user avatar
  • 28.5k
0 votes
1 answer
275 views

Getting all loaded jars' file path on runtime java 17

I have a solution that is basically code from this answer https://stackoverflow.com/a/46709196 Code is compiled on jdk11 but I would like it to run on java17 runtime. So, in runtime my class loader is ...
ebc149's user avatar
  • 16
0 votes
0 answers
26 views

How to unloaded a custom classloader, when after use

I define a custom classloader PluginClassLoader, and I use it execute task, execute one task will create one PluginClassLoader。 After a while, my jvm report "java.lang.Out0fMemoryError: ...
hehe's user avatar
  • 173
1 vote
3 answers
91 views

Can't use static variable in @Advice.OnMethodEnter method in opentelemetry javaagent extension

I'm trying to create an extension for opentelemetry javaagent. I need some static variables outside the methods to handle spans. But I get the error java.lang.ClassNotFoundException for a class where ...
Valeriy K.'s user avatar
  • 2,658
0 votes
0 answers
54 views

Number of the same anonymous class(TypeReference) declarations

I'm working on a project where we have to deal with a number of JSON entities and an SDK to make calls for that JSONs. To map JSON to DTO we use the Jackson library and TypeReference class. Let's say ...
Andrii Yampolskyi's user avatar
0 votes
0 answers
208 views

Java ASM bytecode manipulation - add code to constructor of a library class

I have code to insert instructions into the constructor of a class from a third party library (okhttp3.OkHttpClient in this case). Disassembled class shows the added line. However, I am not sure how ...
rysv's user avatar
  • 2,446
0 votes
1 answer
145 views

Java ASM ClassReader fails with java.io.IOException: Class not found

I am trying to instrument OkHttpClient builder class. However, I am not able to create ClassReader in the first place. import org.objectweb.asm.ClassReader; ... // this works meaning dependency from ...
rysv's user avatar
  • 2,446
0 votes
1 answer
43 views

How to use class loader to hack the Singleton Pattern (create multiple instances of Singleton with different classloaders)

I read this :Breaking of sinlgleton by two different class loaders But I can't create more than one instance of a Singleton with more than one class loader. Can some one help me provide an example of ...
Jenny Lian's user avatar
2 votes
1 answer
52 views

Maven plugin: get access to the "same classloader" as when running tests?

I'm trying to develop a Maven plugin that looks for certain classes and generates specific documentation for them. I've built a POC as a unit test. I'm trying to convert that now to a Maven plugin. ...
Stijn Hooft's user avatar
0 votes
1 answer
165 views

Java ASM byte code manipulation to inject code into a method not working

I want to inject some code into an existing class/method. But I am unable to get the classloader to "find" the class in order to use the modified byte code. MyClassInjector.java import org....
rysv's user avatar
  • 2,446

1
2 3 4 5
83