Skip to content

Commit c6c2d86

Browse files
author
kananindzya
committed
load class from parent classloader
1 parent 8e8336e commit c6c2d86

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

apm-agent-core/src/test/java/co/elastic/apm/agent/TestClassWithDependencyRunner.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
* the Apache License, Version 2.0 (the "License"); you may
1212
* not use this file except in compliance with the License.
1313
* You may obtain a copy of the License at
14-
*
14+
*
1515
* http://www.apache.org/licenses/LICENSE-2.0
16-
*
16+
*
1717
* Unless required by applicable law or agreed to in writing,
1818
* software distributed under the License is distributed on an
1919
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -197,10 +197,19 @@ protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundE
197197
try {
198198
// First, check if the class has already been loaded
199199
Class<?> c = findLoadedClass(name);
200+
ClassLoader parent = getParent();
200201
if (c == null) {
201-
c = findClass(name);
202-
if (resolve) {
203-
resolveClass(c);
202+
try {
203+
if (parent != null) {
204+
c = parent.loadClass(name);
205+
}
206+
} catch (ClassNotFoundException e) {
207+
}
208+
if (c == null) {
209+
c = findClass(name);
210+
if (resolve) {
211+
resolveClass(c);
212+
}
204213
}
205214
}
206215
return c;

apm-agent-plugins/apm-mongoclient-plugin/src/test/java/co/elastic/apm/agent/mongoclient/MongoClientSyncVersionIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
* the Apache License, Version 2.0 (the "License"); you may
1212
* not use this file except in compliance with the License.
1313
* You may obtain a copy of the License at
14-
*
14+
*
1515
* http://www.apache.org/licenses/LICENSE-2.0
16-
*
16+
*
1717
* Unless required by applicable law or agreed to in writing,
1818
* software distributed under the License is distributed on an
1919
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

0 commit comments

Comments
 (0)