Skip to content

Commit

Permalink
Remove poor use of parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Dec 14, 2021
1 parent c5d2e3b commit 80f938a
Showing 1 changed file with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,12 @@ private static <T> T doPrivileged(PrivilegedAction<T> action) {
* Byte Buddy agent.
*/
public static Instrumentation getInstrumentation() {
return doGetInstrumentation(true);
Instrumentation instrumentation = doGetInstrumentation();
if (instrumentation == null) {
throw new IllegalStateException("The Byte Buddy agent is not initialized or unavailable");
} else {
return instrumentation;
}
}

/**
Expand Down Expand Up @@ -605,12 +610,12 @@ public static Instrumentation install(ProcessProvider processProvider) {
* @return An instrumentation instance representing the currently running JVM.
*/
public static synchronized Instrumentation install(AttachmentProvider attachmentProvider, ProcessProvider processProvider) {
Instrumentation instrumentation = doGetInstrumentation(false);
Instrumentation instrumentation = doGetInstrumentation();
if (instrumentation != null) {
return instrumentation;
}
install(attachmentProvider, processProvider.resolve(), WITHOUT_ARGUMENT, AgentProvider.ForByteBuddyAgent.INSTANCE, false);
return doGetInstrumentation(true);
return getInstrumentation();
}

/**
Expand Down Expand Up @@ -757,26 +762,19 @@ private static String quote(String value) {

/**
* Performs the actual lookup of the {@link java.lang.instrument.Instrumentation} from an installed
* Byte Buddy agent, or {@code null} if not present.
* Byte Buddy agent and returns the instance, or returns {@code null} if not present.
*
* @param required {@code true} if a {@code null} return value is prohibited.
* @return The Byte Buddy agent's {@link java.lang.instrument.Instrumentation} instance.
*/
@Nullable
@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "Legal outcome where reflection communicates errors by throwing an exception")
private static Instrumentation doGetInstrumentation(boolean required) {
Instrumentation instrumentation;
private static Instrumentation doGetInstrumentation() {
try {
instrumentation = (Instrumentation) Class.forName(Installer.class.getName(), true, ClassLoader.getSystemClassLoader())
return (Instrumentation) Class.forName(Installer.class.getName(), true, ClassLoader.getSystemClassLoader())
.getMethod(INSTRUMENTATION_METHOD)
.invoke(STATIC_MEMBER);
} catch (Exception ignored) {
instrumentation = UNAVAILABLE;
}
if (required && instrumentation == null) {
throw new IllegalStateException("The Byte Buddy agent is not initialized or unavailable");
} else {
return instrumentation;
return UNAVAILABLE;
}
}

Expand Down

0 comments on commit 80f938a

Please sign in to comment.