Attempt to detect system property mangling prior to loading ByteBuddy. #3164
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If the user stubs their System properties (e.g. to test code that handles System properties to determine the platform), then they may unexpectedly hit the issue that ByteBuddy will attempt to fork a subprocess upon being installed, and that relies on the JVM Process class. Internally, the Process class makes a call to 'System.getProperty(os.name)', which results in a NullPointerException being raised if the property does not exist.
When this exception occurs, it bubbles up to Mockito in the shape of a very confusing error message, which we should ideally try to avoid.
This change adds a check for this edge case prior to loading ByteBuddy so that a meaningful error message can be raised that instructs the user on how to mitigate this issue.
Example reproduction:
Current behaviour:
Using FernFlower, the code at
java.base/java.lang.ProcessImpl.<clinit>(ProcessImpl.java:170)
is the following:This is probably technically a JRE bug, as it is making the expectation that a mutable global singleton is not being mutated in a specific way, but it probably makes sense to check for it here for now to prevent confusing error messages on Mockito's side of things and to prevent spurious issues being raised against the project.