Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for NullPointerException on detach() #395

Merged
merged 1 commit into from Sep 21, 2021

Conversation

aburaksahin
Copy link
Contributor

When a detach() is invoked on a CtClass object, it throws a NullPointerException 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 unexpected NullPointerExceptions. It is not specifically twice detach() invocations in a row that results in that error. My code calls ClassPool.getDefault().get() once and detaches it safely, however, once I perform that cycle again it results in NullPointerException. As I understand from the documentation ClassPool#get(String) reads from the class file and returns CtClass object and on the other hand, detach() causes that CtClass object to be removed from the cache. It is a natural expectation that a new CtClass object should be created by reading the .class file once again when user calls ClassPool.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.

@chibash chibash merged commit 52629ee into jboss-javassist:master Sep 21, 2021
@chibash
Copy link
Member

chibash commented Sep 21, 2021

Thanks, you're right.

@SACHDEVHITESH
Copy link

SACHDEVHITESH commented Jan 19, 2023

I am still getting the null pointer issue in the version 3.27.0-GA

Caused by: java.lang.NullPointerException
at javassist.ClassPool.cacheCtClass(ClassPool.java:236)
at javassist.CtClass.detach(CtClass.java:1427)
at com.microsoft.intune.mam.TransformationUnit.writeClassesToDirectory(TransformationUnit.java:275)
at com.microsoft.intune.mam.TransformationUnit.writeOutput(TransformationUnit.java:126)
at com.microsoft.intune.mam.BuildTimeMamifier.mamify(BuildTimeMamifier.java:131)
at com.microsoft.intune.mam.MamifyTransformBase.transform(MamifyTransformBase.java:195)
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:284)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:69)
... 126 more

New issue Link
https://github.com/jboss-javassist/javassist/issues/442

@zztracy
Copy link

zztracy commented May 29, 2023

I am still getting the null pointer issue in the version 3.27.0-GA

Caused by: java.lang.NullPointerException at javassist.ClassPool.cacheCtClass(ClassPool.java:236) at javassist.CtClass.detach(CtClass.java:1427) at com.microsoft.intune.mam.TransformationUnit.writeClassesToDirectory(TransformatinUnit.java:275) at com.microsoft.intune.mam.TransformationUnit.writeOutput(TransformationUnit.java:126) at com.microsoft.intune.mam.BuildTimeMamifier.mamify(BuildTimeMamifier.java:131) at com.microsoft.intune.mam.MamifyTransformBase.transform(MamifyTransformBase.java:195) at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:284) at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:69) ... 126 more

New issue Link
https://github.com/jboss-javassist/javassist/issues/442

the code was committed on 2021/09/21, and the 3.27.0-GA was released on 2020/03/19. You need 3.29.0-GA which is released after the code solved date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants