paketo-buildpacks/libjvm

Don't add debug config if it's already present

dmikusa opened this issue · 0 comments

Expected Behavior

Current Behavior

Steps to Reproduce

If you set JAVA_TOOL_OPTIONS to contain Java debug info, like -agentlib:jdwp=transport=dt_socket,server=y,address=%s,suspend=%s and then set BPL_DEBUG_ENABLED=true. You'll end up with debug setting specified twice and the JVM will fail to start. The buildpack helper should not add them if it already exists.

Possible Solution

The buildpack will need to look at JAVA_TOOL_OPTIONS and do a fuzzy search for -agentlib:jdwp=transport=dt_socket,server=y,address=%s,suspend=%s. Possibly by looking for an arg that starts with -agentlib:jdwp. If present, log a message and indicate that it was not added a second time. If not present, add it.

This needs to be fixed in both Java 8 & Java 9+ helpers.

Motivations

This can also impact cases where you use one process type through /cnb/process/* to invoke a process type contributed by a libjvm powered buildpack. In this case, the launcher will run twice and can cause the JVM agent properties to be added multiple times.