Bytebuddy Java Agent: AgentBuilder affects control flow of a second, unrelated AgentBuilder

Jo Bo

So I am implementing a Java Agent that installs multiple AgentBuilder, one of them only if an environment variable was defined correctly. The problem I face is that the behavior of a second AgentBuilder changes depending on whether the optional one was installed. To me it seems like installing the optional AgentBuilder affects which methods, that are instrumented by the second unrelated AgentBuilder, get called and how often.

if (EnvVar.isTrue()) {
            // These methods are customs so I don't have to rewrite the whole AgentBuilder-chain...
            getAgentBuilder1(inst, tempFolder).installOn(inst);
        }

getAgentBuilder2(inst, tempFolder).installOn(inst);

The AgentBuilder1 uses the following type matching:

ElementMatchers.isSubTypeOf(InputStream.class)
   .and(
        ElementMatchers.not(
            ElementMatchers.namedOneOf(InflaterInputStream.class.getName())
            .or(ElementMatchers.isPrivate())
                           )
       )

and the AgentBuilder2 this one:

ElementMatchers.namedOneOf(Class.class.getName(), ClassLoader.class.getName());

Now the transformer for AgentBuilder1 uses an Advice to print a log message when the read(...)-method of an InputStream was called, and AgentBuilder2 prints a log message when the ClassLoader.getResource(...)-method or the Class.getResource(...)-method was called.

Everything works as expected, apart from the fact that the AgentBuilder2 logs a lot more resources if AgentBuilder1 was installed than if it wasn't installed - while instrumenting the exact same program... It looks like the Class.getResource(...) method is being called much more often if AgentBuilder1 was installed. Any Ideas?

Rafael Winterhalter

Byte Buddy invokes these methods. If you want to instrument classes that might already be loaded, you would need to use a retransformation strategy. Also, I would recommend to combine these agents in a single builder and only install it once.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

ByteBuddy AgentBuilder not working when running JUnit tests

Referring to a dynamically added method in ByteBuddy AgentBuilder

ByteBuddy - Read class annotations in a java agent

Exception on invocation of java agent instrumented via ByteBuddy

Java control flow

Java flow-control

Java: Exceptions as control flow?

Is there a way to retrieve the caller "object" in a Java agent using ByteBuddy?

Unable to understand the flow control in java

Java Control Flow Graphs Library

Tool for generating control flow in Java

Java flow control by throwing exceptions

Cannot transform class with ByteBuddy Agent

Bytebuddy: Method not being called in agent

Java 8 Map<String, Runnable> Control Flow

JAVA trouble with control flow and strings in school project

Use ternary operator for flow control in Java

ByteBuddy agent to replace one method param with another

Increasing an element in a numpy matrix also affects different matrix and unrelated rows

Flow types throwing error on seemingly unrelated types

How does the control flow for break statements work in nested loops? (Java)

How does control flow in Java8 collectors?

Control flow in android studio from layout file to MainActivity.java

Creating a transformer to add a class from an agent using ByteBuddy

How to create a bytebuddy agent that intercepts a field setter from annotated field?

How to take the exception thrown by a constructor using a ByteBuddy agent?

Multiple custom controls affects control visibility

Slider with a control template thumb affects the value?

Swift control flow:

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    pump.io port in URL

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  14. 14

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  15. 15

    How to use merge windows unallocated space into Ubuntu using GParted?

  16. 16

    flutter: dropdown item programmatically unselect problem

  17. 17

    Pandas - check if dataframe has negative value in any column

  18. 18

    Nuget add packages gives access denied errors

  19. 19

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  20. 20

    Generate random UUIDv4 with Elm

  21. 21

    Client secret not provided in request error with Keycloak

HotTag

Archive