Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent the need for -javaagent on Java 9+ and JMockit 1.42+ #546

Closed
Thunderforge opened this issue Aug 24, 2018 · 2 comments
Closed

Prevent the need for -javaagent on Java 9+ and JMockit 1.42+ #546

Thunderforge opened this issue Aug 24, 2018 · 2 comments
Labels

Comments

@Thunderforge
Copy link

Thunderforge commented Aug 24, 2018

In #544, it was asked to remove the need for the -Djdk.attach.allowAttachSelf parameter, which appears on JMockit 1.41 and Java 9+. The response was that this would be replaced with -javaagent on JMockit 1.42 (and the discussion was frustratingly locked so that no further clarification questions could be asked).

The same underlying problem remains though: it is very inconvenient to have to add a flag to every run in Maven (and Gradle?), as well as IDE runs for individual tests. It is also a common newbie mistake to forget to add these flags, and we've already had several closed issues where that was what people forgot to do. In other words, having a mandatory flag is making JMockit harder to use than it should be.

The best solution would be to create a workaround, like ByteBuddy did, so that neither a -Djdk.attach.allowAttachSelf parameter nor a -javaagent parameter needs to be added. If this is not possible, then please explain what the obstacles are (in the hopes that someone else can figure out how to overcome the obstacles and submit a PR).

@rliesenfeld
Copy link
Member

There are several technical difficulties in getting dynamic Java agent loading (through use of the Attach API) to work. It requires several hacks, and it's ultimately not reliable (for example, in certain cases Maven/Gradle ends up loading Expectations subclasses before the agent gets loaded, preventing JMockit's ClassFileTransformer from doing its job).

"-javaagent", on the other hand, is the standard way to get a Java agent loaded. With a good IDE (for example, IntelliJ), all you need to do is add the parameter in the test execution command line (for example, in Maven Surefire plugin configuration); the IDE should automatically add it to the command line whenever a test is executed (with IntelliJ, which I use, it's working fine - I imagine Netbeans should be ok too as it uses Maven for test execution).

@rliesenfeld
Copy link
Member

See #545 for more info.

@jmockit jmockit deleted a comment from Thunderforge Apr 18, 2019
@jmockit jmockit locked and limited conversation to collaborators Apr 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

2 participants