Fix JavaAgent precondition and add a unit test.

https://rbcommons.com/s/twitter/r/770/