Skip to content

Commit

Permalink
Added checks for non-installed agent when using convenience methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Winterhalter committed Nov 30, 2015
1 parent abb4357 commit e42ef1d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Expand Up @@ -2002,10 +2002,14 @@ public ClassFileTransformer installOn(Instrumentation instrumentation) {
@Override
public ClassFileTransformer installOnByteBuddyAgent() {
try {
return installOn((Instrumentation) ClassLoader.getSystemClassLoader()
Instrumentation instrumentation = (Instrumentation) ClassLoader.getSystemClassLoader()
.loadClass(INSTALLER_TYPE)
.getDeclaredField(INSTRUMENTATION_FIELD)
.get(STATIC_FIELD));
.get(STATIC_FIELD);
if (instrumentation == null) {
throw new IllegalStateException("The Byte Buddy agent is not installed");
}
return installOn(instrumentation);
} catch (RuntimeException exception) {
throw exception;
} catch (Exception exception) {
Expand Down
Expand Up @@ -492,10 +492,14 @@ public AgentBased(Instrumentation instrumentation, ClassLoadingDelegate classLoa
*/
public static ClassFileLocator fromInstalledAgent(ClassLoader classLoader) {
try {
return new AgentBased((Instrumentation) ClassLoader.getSystemClassLoader()
Instrumentation instrumentation = (Instrumentation) ClassLoader.getSystemClassLoader()
.loadClass(INSTALLER_TYPE)
.getDeclaredField(INSTRUMENTATION_FIELD)
.get(STATIC_FIELD), classLoader);
.get(STATIC_FIELD);
if (instrumentation == null) {
throw new IllegalStateException("The Byte Buddy agent is not installed");
}
return new AgentBased(instrumentation, classLoader);
} catch (RuntimeException exception) {
throw exception;
} catch (Exception exception) {
Expand Down
Expand Up @@ -120,10 +120,14 @@ protected ClassReloadingStrategy(Instrumentation instrumentation, Engine engine,
*/
public static ClassReloadingStrategy fromInstalledAgent() {
try {
return new ClassReloadingStrategy((Instrumentation) ClassLoader.getSystemClassLoader()
Instrumentation instrumentation = (Instrumentation) ClassLoader.getSystemClassLoader()
.loadClass(INSTALLER_TYPE)
.getDeclaredField(INSTRUMENTATION_FIELD)
.get(STATIC_FIELD));
.get(STATIC_FIELD);
if (instrumentation == null) {
throw new IllegalStateException("The Byte Buddy agent is not installed");
}
return new ClassReloadingStrategy(instrumentation);
} catch (RuntimeException exception) {
throw exception;
} catch (Exception exception) {
Expand Down

0 comments on commit e42ef1d

Please sign in to comment.