Merge pull request #1350 from jpbempel/jpbempel/improveJFRMessage

Add fix suggestion when JFR API not found
This commit is contained in:
Jean-Philippe Bempel 2020-04-06 16:35:38 +02:00 committed by GitHub
commit 176b9c0121
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 7 deletions

View File

@ -49,8 +49,28 @@ public final class ControllerFactory {
| InstantiationException
| IllegalAccessException
| InvocationTargetException e) {
throw new UnsupportedEnvironmentException(
"The JFR controller could not find a supported JFR API", e);
String exMsg =
"The JFR controller could not find a supported JFR API" + getFixProposalMessage();
throw new UnsupportedEnvironmentException(exMsg, e);
}
}
private static String getFixProposalMessage() {
try {
String javaVersion = System.getProperty("java.version");
if (javaVersion == null) {
return "";
}
String javaVendor = System.getProperty("java.vendor", "");
if (javaVersion.startsWith("1.8")) {
if (javaVendor.startsWith("Azul Systems")) {
return ", use Azul zulu version 1.8.0_212+";
}
// TODO Add version minimum once JFR backported into OpenJDK distros
}
return ", use OpenJDK 11+ or Azul zulu version 1.8.0_212+";
} catch (Exception ex) {
return "";
}
}
}

View File

@ -1,5 +1,6 @@
package com.datadog.profiling.controller;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.condition.JRE.JAVA_8;
@ -19,10 +20,18 @@ public class ControllerFactoryTest {
@Test
@EnabledOnJre({JAVA_8})
public void testCreateControllerJava8() {
assertThrows(
UnsupportedEnvironmentException.class,
() -> {
ControllerFactory.createController(config);
});
UnsupportedEnvironmentException unsupportedEnvironmentException =
assertThrows(
UnsupportedEnvironmentException.class,
() -> {
ControllerFactory.createController(config);
});
String expected =
"The JFR controller could not find a supported JFR API, use OpenJDK 11+ or Azul zulu version 1.8.0_212+";
if ("Azul Systems, Inc.".equals(System.getProperty("java.vendor"))) {
expected =
"The JFR controller could not find a supported JFR API, use Azul zulu version 1.8.0_212+";
}
assertEquals(expected, unsupportedEnvironmentException.getMessage());
}
}