Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#noissue] PinpointPluginTestSuite JDK9+ compatibility #7415

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ private void prepareAgentModule(final ClassLoader classLoader, JavaModule agentM
agentModule.addExports("com.navercorp.pinpoint.profiler", bootstrapModule);
agentModule.addReads(bootstrapModule);

// Error:class com.navercorp.pinpoint.bootstrap.AgentBootLoader$1 cannot access class com.navercorp.pinpoint.test.PluginTestAgent (in module pinpoint.agent)
// because module pinpoint.agent does not export com.navercorp.pinpoint.test to unnamed module
agentModule.addExports("com.navercorp.pinpoint.test", bootstrapModule);

// Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected void java.net.URLClassLoader.addURL(java.net.URL) accessible:
// module java.base does not "opens java.net" to module pinpoint.agent
// at pinpoint.agent/pinpoint.agent/com.navercorp.pinpoint.profiler.instrument.classloading.URLClassLoaderHandler.<clinit>(URLClassLoaderHandler.java:44)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.navercorp.pinpoint.common.util.ArrayUtils;
import com.navercorp.pinpoint.common.util.SystemProperty;
import com.navercorp.pinpoint.exception.PinpointException;
import com.navercorp.pinpoint.test.plugin.util.StringUtils;
import org.eclipse.aether.resolution.ArtifactResolutionException;
import org.eclipse.aether.resolution.DependencyResolutionException;
import org.junit.internal.runners.statements.RunAfters;
Expand All @@ -32,6 +33,7 @@

import java.io.File;
import java.lang.management.ManagementFactory;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
Expand Down Expand Up @@ -61,6 +63,9 @@ public abstract class AbstractPinpointPluginTestSuite extends Suite {
"/test/target/classes" // pinpoint-test build output directory
};

private static final String FILE_URL_PREFIX = "file:";
private static final String JAVA_9_INTERNAL_CLASSLOADER_PREFIX = "jdk.internal.loader.ClassLoaders$";

private final List<String> requiredLibraries;
private final List<String> mavenDependencyLibraries;
private final String testClassLocation;
Expand Down Expand Up @@ -157,10 +162,33 @@ private String resolveTestClassLocation(Class<?> testClass) {


private List<String> getClassPathList(String[] classPathCandidates) {
List<String> result = new ArrayList<String>();

ClassLoader cl = getClass().getClassLoader();
if (cl.getClass().getName().startsWith(JAVA_9_INTERNAL_CLASSLOADER_PREFIX)) {
return getJava9ClassPathList(classPathCandidates);
}
return getClassPathList(cl, classPathCandidates);
}

private List<String> getJava9ClassPathList(String[] classPathCandidates) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The design of classloader dependent code seems to be bad.
If everything is fine, your code looks much better.
Could you replace the old code with yours?

     cl = cl.getParent();
     if (cl == null) {
         break;
      }

There may be a problem with the above code, but I'm not sure.
Please check that it works properly in all tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your review @emeroad
I'll change the old code and make sure there are no problems with all the tests.
When this test is completed i will commit again :)

String classPath = SystemProperty.INSTANCE.getProperty("java.class.path");
if (StringUtils.isEmpty(classPath)) {
return new ArrayList<String>();
}
String[] paths = classPath.split(":");
URL[] urls = new URL[paths.length];
for (int i = 0; i < paths.length; i++) {
try {
urls[i] = new URL(FILE_URL_PREFIX + paths[i]);
} catch (MalformedURLException e) {
System.out.println("Skip - " + paths[i] + " check url format");
}
}
Collection<String> requiredLibraries = findLibraries(urls, classPathCandidates);
return new ArrayList<String>(requiredLibraries);
}

private List<String> getClassPathList(ClassLoader cl, String[] classPathCandidates) {
List<String> result = new ArrayList<String>();
while (true) {
if (cl instanceof URLClassLoader) {
URLClassLoader ucl = ((URLClassLoader) cl);
Expand All @@ -174,7 +202,6 @@ private List<String> getClassPathList(String[] classPathCandidates) {
break;
}
}

return result;
}

Expand Down