fix: guard JDTUtils.searchDecompiledSources NPE via OSGi WeavingHook#22
Open
runchen0919 wants to merge 1 commit into
Open
fix: guard JDTUtils.searchDecompiledSources NPE via OSGi WeavingHook#22runchen0919 wants to merge 1 commit into
runchen0919 wants to merge 1 commit into
Conversation
JDT.LS has an unfixed bug (eclipse-jdtls#3083) where JDTUtils.searchDecompiledSources() throws NPE in the MethodInvocation branch due to a missing finder.initialize() call. This crashes "Find References" and "Go to Implementation" when classpath JARs lack source attachments. This fix registers an OSGi WeavingHook that intercepts class loading of JDT.LS handler classes and wraps call sites to searchDecompiledSources in try-catch(NPE), returning Collections.emptyList() on catch. The approach patches callers (not JDTUtils itself) because JDTUtils is loaded during JDT.LS initialization before our bundle starts, while handler classes are lazily loaded on first LSP request. Key design choices: - Pre-scan classes with bare ClassVisitor before COMPUTE_FRAMES to avoid ClassNotFoundException in OSGi for unrelated classes - SafeClassWriter falls back to java/lang/Object when type resolution fails across bundle boundaries - Match by owner+method name only (no descriptor) for version resilience - ASM 9.7 embedded as Private-Package via bnd Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
searchDecompiledSourcescall sites intry-catch(NPE)to returnCollections.emptyList()instead of crashingChanges
java-bridge/pom.xmlorg.ow2.asm:asm:9.7(compile) andorg.osgi:osgi.core:8.0.0(provided)java-bridge/bnd.bndorg.osgi.framework.hooks.weavingimport,Private-Packagefor ASM embeddingJDTUtilsPatcher.javaBazelActivator.javaJDTUtilsPatcherTest.javadocs/weaving-hook-npe-fix.mdKey Design Choices
SKIP_DEBUG | SKIP_FRAMESto skip classes without the target call site, avoidingClassNotFoundExceptionfromCOMPUTE_FRAMESin OSGijava/lang/Objectwhen cross-bundle type resolution failsTest plan
mvn test -Dtest=JDTUtilsPatcherTest)mvn compilesucceeds, ASM classes embedded in bundleorg.osgi.framework.hooks.weavingimportFailed to patchwarnings in JDT.LS logs🤖 Generated with Claude Code