Fix for NullPointerException on detach() #395
Merged
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.
When a
detach()
is invoked on aCtClass
object, it throws aNullPointerException
as mentioned in #370 and in #258, I have seen your response but I don't think it is a good practice to let users receive unexpectedNullPointerException
s. It is not specifically twicedetach()
invocations in a row that results in that error. My code callsClassPool.getDefault().get()
once and detaches it safely, however, once I perform that cycle again it results inNullPointerException
. As I understand from the documentationClassPool#get(String)
reads from the class file and returnsCtClass
object and on the other hand,detach()
causes thatCtClass
object to be removed from the cache. It is a natural expectation that a newCtClass
object should be created by reading the.class
file once again when user callsClassPool.getDefault().get(String)
and it must allow users to safely detach from the class pool.My fix is just a no-brainer, and probably just evades the problem rather than solving it.