Skip to content

Cross-file j2d/refs#1

Closed
chrismwendt wants to merge 1 commit into
masterfrom
cross-file-j2d
Closed

Cross-file j2d/refs#1
chrismwendt wants to merge 1 commit into
masterfrom
cross-file-j2d

Conversation

@chrismwendt

Copy link
Copy Markdown
Contributor

(no intention to merge)

This is my attempt to see if cross-file j2d/refs would work by using SymbolSolverCollectionStrategy as shown in https://javaparser.org/setting-up-for-analysing-a-whole-project/

It currently doesn't work, and I seem to have hit a roadblock. Take for example this call to postIndex:

https://github.com/sourcegraph/lsif-java/blob/4cf52ba51fb1439afbb61e393c4e4cfafc3cd378/src/main/java/ProjectIndexer.java#L57

When I print out the value of System.out.println(n.resolve());, where n is a MethodCallExpr for postIndex, I get:

ReflectionMethodDeclaration{method=public void DocumentIndexer.postIndex()}

instead of a JavaParserMethodDeclaration. This is problematic because:

getWrappedNode is present only on the subclasses of the Resolved* declarations that derive from JP AST nodes (such as JavaParserClassDeclaration).

From https://static.javadoc.io/com.github.javaparser/javaparser-core/3.13.2/com/github/javaparser/resolution/declarations/AssociableToAST.html#toAst--

ReflectionMethodDeclaration cannot be cast to JavaParserMethodDeclaration. That means I can't call getWrappedNode on it.

I did a bunch of GitHub code searches for other uses of SymbolSolverCollectionStrategy, getWrappedNode, etc. and haven't found any workaround. It seems that Reflection* classes come from jars:

https://github.com/opensathishrtskumar/StaticAnalyzer/blob/cd889d4b9fd631ba13dccce1fce340005ea76e86/src/com/analyzer/visitor/GeneralVisitor.java#L75-L82

@chrismwendt

Copy link
Copy Markdown
Contributor Author

Subsumed by #2

Strum355 added a commit that referenced this pull request Oct 1, 2020
jupblb added a commit that referenced this pull request May 28, 2026
JavaToolchainPlugin (now removed) used to mask three JDK-17+ issues in
the javacPlugin project by pinning its compile JDK to 11, stripping flags
from the doc task, and forcing --release 11 on all Java code. With the
plugin gone, all three surface:

1. JDK 14 added Plugin.autoStart(), so JDK 17/21 javac eagerly enumerates
   ServiceLoader<Plugin> providers from the processor path (or, if absent,
   the compile classpath). During incremental compilation our own
   META-INF/services/com.sun.source.util.Plugin descriptor sits on the
   classpath but SemanticdbPlugin.class isn't built yet, so ServiceLoader
   throws 'Provider com.sourcegraph.semanticdb_javac.SemanticdbPlugin not
   found'.

   Fix: pass an explicit empty -processorpath to javac so it doesn't scan
   our own output directory for Plugin providers. The descriptor stays in
   src/main/resources/ so that internal sbt consumers (e.g. the
   'minimized' test project that depends on javacPlugin via dependsOn)
   and the Bazel build can still find it.

2. javadoc rejects the '-g' flag that was previously added via
   'javacOptions += "-g"'. The old plugin worked around this with
   '(doc / javacOptions) --= List("-g")'.

   Fix: scope '-g' (and the empty -processorpath from #1) to
   'Compile / compile / javacOptions' so neither flag reaches the doc
   task. (Plain 'Compile / javacOptions' is inherited by 'Compile / doc'
   as well.)

3. sbt-assembly's shader ships an older ASM that cannot read class major
   version 61 (JDK 17). When sbt runs under JDK 17/21 the fat jar ends up
   with SemanticdbVisitor (and other classes that hit protobuf types)
   silently un-shaded, so at runtime javac fails with
   'NoClassDefFoundError: com/google/protobuf/ProtocolMessageEnum'.

   Fix: add 'Compile / javacOptions ++= Seq("--release", "11")' to
   javaOnlySettings so Java code always emits class version 55, which the
   shader handles, regardless of which JDK runs sbt.
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.

1 participant