Monday 22 May 2017

Configuring BMUnit for the latest JDK9 EA releases

The latest JDK9 EA access releases (jdk-ea+169 and subsequent) now incorporates a restriction that affects use of the BMUnit package (BMUnit integrates Byteman with JUnit and TestNG -- see the 2nd Byteman tutorial for full details).

BMUnit makes it easy to use Byteman in unit and integration tests. It provides @BMRule and @BMScript annotations used to annotate test methods or test classes. These annotations specify the Byteman rules you want injected into your application, test or JDK runtime classes prior to running a test. In order for that to work, BMUnit needs to ensure the Byteman agent is loaded into the current test JVM before running the annotated tests.

As of the Early Access 169 release, JDK9 now includes a check which, by default, stops code using the Agent Load library to hoist an agent into the same JVM. This is provided for users who want to guarantee that code they have deployed in their classpath cannot load an agent in order to escalate its own privilege level (agents like Byteman have very special powers, most notably the ability to rewrite method bytecode).

Of course, that kind of hostage scenario should never be an issue. Users ought to be in full control of what code gets placed in their classpath. So, they should not have to be concerned that a deployment might attempt to use this capability unless it is intended Anyway, irrespective of the rationale for its inclusion, this restriction has been added to JDK9 as a belt and braces security feature for the  super-paranoid^H^H^H^H^H^H -safety conscious user.

Of course, this restriction affects BMUnit because it has to use the Agent Load library to hoist the Byteman agent into the running JVM in order then to be able to inject code changes required for unit tests. Having BMUnit load the agent automatically is much more convenient than configuring the relevant agent options on the Java command line. In particular, BMUNit provides the BMUnitConfig annotation, allowing you to easily configure/reset all the extra arguments that you would otherwise have to squeeze into one long command line string. So, it is much better to be able to remove this restriction and rely on self-hoisting when running your BMUnit tests.

Luckily, it is very simple to disable the restriction. The JVM will allow an agent self-hoist to proceed if a specific system property, jdk.attach.allowAttachSelf, is set to the String value "true". This is a read-only property so it has to be set when the test JVM is started.

If you are using maven then this means that you need to modify the configuration for your maven surefire or failsafe tests to specify the required system property at JVM start setting using the argLine configuration element

<argLine>-Djdk.attach.allowAttachSelf=true</argLine>

n.b. specifying this value as a property element in the properties configuration element will not work.

If you are running from the command line or using some other tool then ensure you pass the property setting on the java command line using the -D command flag

  java -Djdk.attach.allowAttachSelf=true ...

It is probably worth adding this to all your BMUnit test configurations even if you are not yet using jdk9-ea+169 or later releases. You will be prepared for when you do eventually upgrade and setting the property will be harmless since it will ignored by any earlier JDK releases (including on JDK8).

Thursday 27 April 2017

Byteman 3.0.10 and 4.0.0-BETA5 have been released


Byteman 3.0.10 is now available from the Byteman downloads page and from the Maven Central repository. It is accompanied by a corresponding 4.0.0-BETA5 release for JDK9.
3.0.10 is a minor update for the preceding release 3.0.9. It fixes a couple of bugs in the type checker. It is intended for use on JDK8 and earlier.
4.0.0-BETA5 is the corresponding release for use with JDK9. As well as providing the type checker fixes it also includes fixes to a couple of bugs found when testing on jdk9. One is a genuine bug in Byteman, the other works around a limitation on the use of method handles as currently implemented by JDK9.
More details can be found in the Release Notes.
Note that release 3.0.9 is intended for use on JDK6-8 whereas preview release Byteman 4.0.0-BETA4 is intended for use on the latest early access releases of JDK9 (jdk9-ea+165 and later).
Note also that 4.0.0-BETA4 should still work compatibly with 3.0.10 on JDK6-8.
 

Wednesday 19 April 2017

Byteman 3.0.9 and 4.0.0-BETA4 have been released


Byteman 3.0.9 is now available from the Byteman downloads page and from the Maven Central repository. It is accompanied by a corresponding 4.0.0-BETA4 release for JDK9.
3.0.9 is a minor update for the preceding release 3.0.8. It fixes one bug in the 3.08 release for jdk8 which was latent but hidden by a second bug (also fixed :-).
The same bug does actually manifest in release 4.0.0-BETA3 for jdk9-ea+151 (the jdk9 pre-release version which accompanied 3.0.8) courtesy of other Byteman changes made to accommodate Jigsaw. The BETA4 release fixes this bug and also includes updates to accommodate further changes made to Jigsaw in versions up to and including jdk9-ea+165.
More details can be found in the Release Notes.

Note that release 3.0.9 is intended for use on JDK6-8 whereas preview release Byteman 4.0.0-BETA4 is intended for use on the latest early access releases of JDK9 (jdk9-ea+165 and later).
With luck 4.0.0-BETA4 will be the last BETA release for jdk9 and the current parallel release streams will merge when 4.0.0 is released.

Tuesday 7 March 2017

Byteman 3.0.8 has been released

Byteman 3.0.8 is now available from the Byteman downloads page and from the Maven Central repository.


This is a minor update for the preceding release 3.0.7. It fixes a small problem in the top-level pom which was causing artifact resolution issues for some Maven-based projects wishing to consume byteman. It also contains some cosmetic tweaks to the dtest contributed library. More details can be found in the Release Notes.

Note that release 3.0.8 is intended for use on JDK6-8. Preview release Byteman 4.0.0-BETA3 is available for use on early access releases of JDK9.

Friday 3 February 2017

Byteman 3.0.7 has been released

Byteman 3.0.7 is now available from the Byteman downloads page and from the Maven Central repository.

This is an update for the preceding release 3.0.6. It includes a few new features and bug fixes. More details can be found in the Release Notes.

Note that release 3.0.7 is intended for use on JDK6-8. Preview release Byteman 4.0.0-BETA3 is available for use on early access releases of JDK9.

Wednesday 1 February 2017

Byteman 4.0.0-BETA3 has been released

Byteman 4.0.0-BETA3 is now available from the Byteman downloads page and from the Maven Central repository.



This is a preview release allowing Byteman to be used with the latest JDK9 release (Early Access release b151 for JDK 9 and later releases) which includes the Java Platform Module System (JPMS aka Jigsaw). It should also operate as normal on JDK6-8.

Byteman 4.0.0-BETA3 updates the previous BETA2 release to introduce some internal changes which make Byteman operate better on JDK9. In the process it resolves some outstanding issues relating to reference to non-public classes. See the Release Notes for more details.

Tuesday 10 January 2017

Byteman 4.0.0-BETA2 has been released

Byteman 4.0.0-BETA2 is now available from the Byteman downloads page and from the Maven Central repository.



This is a preview release allowing Byteman to be used with the latest JDK9 release (Early Access release b151 for JDK 9) which includes the Java Platform Module System (JPMS aka Jigsaw). Byteman 4.0.0-BETA2 updates the previous BETA1 release to cope with minor changes in the JPMS implementation. It introduces no new functionality.