Skip to content

Commit

Permalink
INSPECTIT-2544: updated agent to support java 9
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Senic authored and mariusoe committed Oct 12, 2017
1 parent 8154e05 commit 9d730be
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
9 changes: 7 additions & 2 deletions dependencies.gradle
Expand Up @@ -175,14 +175,19 @@ dependencies {

/** inspectit.agent.java */
agentJavaProd (
'org.ow2.asm:info.novatec.asm-all-shaded:5.0.4',
'org.ow2.asm:info.novatec.asm-all-shaded:6.0',
'commons-codec:commons-codec:1.6',
'org.slf4j:jcl-over-slf4j:1.7.21',
'org.slf4j:log4j-over-slf4j:1.7.21',
'ch.qos.logback:logback-core:1.1.7',
'ch.qos.logback:logback-classic:1.1.7',
'piccolo:piccolo:1.0.3',
'com.lmax:disruptor:3.3.6'
'com.lmax:disruptor:3.3.6',

// javax.annotation-api needed as we use them, but they are removed in java 9 from java.base module
// currently only to support starting agent with Java 9, but needed if we want to start
// any other component with Java 9 in future
'javax.annotation:javax.annotation-api:1.2'
)

/** inspectit.server */
Expand Down
Expand Up @@ -336,7 +336,7 @@ public static class InspectItClassLoader extends URLClassLoader {
* the urls to search for the classes for.
*/
public InspectItClassLoader(URL[] urls) {
super(urls, null);
super(urls, getParentClassLoader());

try {
File agentFile = getInspectItAgentJarFileLocation();
Expand Down Expand Up @@ -365,6 +365,23 @@ public InspectItClassLoader(URL[] urls) {
ignoreClasses.add(InspectItClassLoader.class.getName());
}

/**
* @return Returns the platform class loader if we are on Java 9 as this one can load needed
* Java classes for us.
*/
private static ClassLoader getParentClassLoader() {
try {
String javaVersion = System.getProperty("java.version");
if (javaVersion.charAt(0) == '9') {
return (ClassLoader) ClassLoader.class.getDeclaredMethod("getPlatformClassLoader", new Class[] {}).invoke(null);
} else {
return null;
}
} catch (Exception e) {
return null;
}
}

/**
* Gets {@link #bootClassLoaderJarFiles}.
*
Expand Down
Expand Up @@ -3,6 +3,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.sameInstance;
import static org.hamcrest.Matchers.theInstance;

import org.mockito.InjectMocks;
Expand Down Expand Up @@ -169,11 +170,12 @@ public void normalUsage() {

@Test
public void normalUsageJavaClass() {
String testInstance = "test";
Exception testCause = new Exception();
Exception testInstance = new Exception(testCause);

char[] field = (char[]) cache.getField(String.class, "value", testInstance, null);
Exception cause = (Exception) cache.getField(testInstance.getClass(), "cause", testInstance, null);

assertThat(field, is(equalTo(testInstance.toCharArray())));
assertThat(cause, is(sameInstance(testCause)));
}

@Test
Expand Down
Expand Up @@ -68,6 +68,11 @@ public enum JavaVersion {
*/
JAVA_1_8,

/**
* Denotes Java version 1.9.
*/
JAVA_1_9,

/**
* Denotes unknown java version.
*/
Expand Down Expand Up @@ -197,6 +202,8 @@ private static JavaVersion getJavaVersion() {
return JavaVersion.JAVA_1_7;
} else if (getJavaVersionMatches("1.8")) {
return JavaVersion.JAVA_1_8;
} else if (getJavaVersionMatches("9")) {
return JavaVersion.JAVA_1_9;
} else {
return JavaVersion.OTHER;
}
Expand Down
5 changes: 5 additions & 0 deletions resources/config/findbugs/findBugsExcludeFilter.xml
Expand Up @@ -38,6 +38,11 @@
<Class name="rocks.inspectit.agent.java.event.AgentMessagesReceivedEvent" />
<Bug pattern="SE_BAD_FIELD" />
</Match>
<Match>
<Class name="rocks.inspectit.agent.java.javaagent.JavaAgent$InspectItClassLoader" />
<Method name="getParentClassLoader" />
<Bug pattern="REC_CATCH_EXCEPTION" />
</Match>
<!-- Agent ignores END -->

<!-- CMR ignores START -->
Expand Down

0 comments on commit 9d730be

Please sign in to comment.