Skip to content

Commit

Permalink
[JENKINS-53445] Trap unrecognized JVM version
Browse files Browse the repository at this point in the history
Let's not fire an NPE when the plugin doesn't know the JVM and ByteCode
versions. Still marking the master-agent as incompatible to prevent any
potential issues.
  • Loading branch information
alecharp committed Jan 29, 2019
1 parent 73741da commit 21b3dce
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Expand Up @@ -91,9 +91,16 @@ private int getMasterBytecodeMajorVersionNumber() {

private boolean isAgentRuntimeCompatibleWithJenkinsBytecodeLevel(String agentMajorMinorVersion) {
Integer masterBytecodeLevel = getMasterBytecodeMajorVersionNumber();
Integer agentVMMaxBytecodeLevel = JDK_VERSION_NUMBER_TO_BYTECODE_LEVEL_MAPPING.get(agentMajorMinorVersion);

return masterBytecodeLevel <= agentVMMaxBytecodeLevel;
try {
Integer agentVMMaxBytecodeLevel = JDK_VERSION_NUMBER_TO_BYTECODE_LEVEL_MAPPING.get(agentMajorMinorVersion);
return masterBytecodeLevel <= agentVMMaxBytecodeLevel;
} catch(NullPointerException e) {
LOGGER.log(Level.WARNING, Messages.JVMVersionMonitor_UnrecognizedAgentJVM(agentMajorMinorVersion));
/*
* Even if the version might be compatible, we still mark the node as incompatible to prevent potential issues.
*/
return false;
}
}

public boolean isCompatible() {
Expand Down
Expand Up @@ -7,4 +7,6 @@ JVMVersionMonitor.OfflineCause=This node is offline because the JVM version of t
JVMVersionMonitor.MarkedOffline=Making {0} offline temporarily due to using an incompatible JVM version between agent and master (master={1}, agent={2})
JVMVersionMonitor.RUNTIME_GREATER_OR_EQUAL_MASTER_BYTECODE=Agent runtime must be greater or equal than the Master bytecode level (strongly recommended minimum)
JVMVersionMonitor.MAJOR_MINOR_MATCH=Agent major.minor must be equal to Master major.minor JVM version (paranoid version)
JVMVersionMonitor.EXACT_MATCH=Agent JVM version must be exactly the same as Master JVM version (paranoid++ version)
JVMVersionMonitor.EXACT_MATCH=Agent JVM version must be exactly the same as Master JVM version (paranoid++ version)

JVMVersionMonitor.UnrecognizedAgentJVM=The agent JVM version {0} is not recognized by the plugin. You might want to open a ticket for the maintainer to complete the compatibility list.
Expand Up @@ -5,8 +5,11 @@
import junitparams.Parameters;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.jvnet.hudson.test.Issue;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

@RunWith(JUnitParamsRunner.class)
Expand Down Expand Up @@ -104,4 +107,13 @@ public int get() {
}).isNotCompatible());
}

@Issue("JENKINS-53445")
@Test
public void shouldNotThrowNPEWhenJVMVersionIsNotRecognized() {
JVMVersionComparator jvmVersionComparator =
new JVMVersionComparator("99.9", "99.9",
JVMVersionComparator.ComparisonMode.RUNTIME_GREATER_OR_EQUAL_MASTER_BYTECODE);
assertNotNull(jvmVersionComparator);
assertFalse(jvmVersionComparator.isCompatible());
}
}

0 comments on commit 21b3dce

Please sign in to comment.