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

VS Code: java modules: ResponseAPDU cannot be resolved to a type #3879

Open
Honza-cz opened this issue Nov 28, 2024 · 2 comments
Open

VS Code: java modules: ResponseAPDU cannot be resolved to a type #3879

Honza-cz opened this issue Nov 28, 2024 · 2 comments

Comments

@Honza-cz
Copy link

Hello,

I am struggling with visual studio code and modules. I am working on project, which needs to use java.base/javax.smartcardio. But VS Code complains "ResponseAPDU cannot be resolved to a type".

The demo class to demonstrate the issue is:

import javax.smartcardio.ResponseAPDU;

public class SmartCardIoDemo {
    public static void main(String[] args) throws Exception {
        System.out.println("start");
        ResponseAPDU rapdu = new ResponseAPDU(new byte[2]);
        System.out.println("end");
    }
}

It can be fixed it by adding module-info.java

module myModule {
    requires java.smartcardio;
}

but this is not possible to do it in our codebase because we don't use java modules. If I run the build and test by maven, then it works fine (without any --add-exports etc).

I tried following change in settings.json but it didn't solve the issue:

{
   "java.jdt.ls.vmargs":"--add-exports=java.base/javax.smartcardio=ALL-UNNAMED -XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx1G -Xms100m -Xlog:disable"
}

I am even bit confused which part (extension) complains about that import, because during opening of the project, I can click through reference of ResponseAPDU to see the decompiled code.

Image
Sample app SmartCardio.zip
App can be executed by mvn clean package exec:java -Dexec.mainClass="com.mycompany.SmartCardIoDemo"

but if I click on run main method, I got this error in terminal:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
        ResponseAPDU cannot be resolved to a type
        ResponseAPDU cannot be resolved to a type

        at com.mycompany.SmartCardIoDemo.main(SmartCardIoDemo.java:11)

Thx in advance for any advice.

@fbricon
Copy link
Collaborator

fbricon commented Nov 28, 2024

Interesting, seems "java.jdt.ls.javac.enabled": "on" fixes it.

enabling-javac.mp4

@Honza-cz
Copy link
Author

That works in that sample application. But in prod repo, beside having access to the module once activating javac, I had to upgrade jdk for java language server to version 23. It somehow broke the compilation / junit test exec. I will see, If I can reproduce it in the sample application.

In the VS code logs, I found this exceptions as this one:

!ENTRY org.eclipse.jdt.core 4 0 2024-11-29 08:52:42.707
!MESSAGE T.getVersion
!STACK 0
java.lang.AssertionError: T.getVersion
	at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:162)
	at jdk.compiler/com.sun.tools.javac.code.Symbol$MethodSymbol.<init>(Symbol.java:1976)
	at jdk.compiler/com.sun.tools.javac.code.Symbol$MethodSymbol$1.<init>(Symbol.java:1982)
	at jdk.compiler/com.sun.tools.javac.code.Symbol$MethodSymbol.clone(Symbol.java:1982)
	at jdk.compiler/com.sun.tools.javac.code.Symbol$MethodSymbol.clone(Symbol.java:1952)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.binaryQualifier(Gen.java:264)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitSelect(Gen.java:2410)
	at org.eclipse.jdt.internal.javac.ProceedOnErrorGen.visitSelect(ProceedOnErrorGen.java:109)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2570)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:859)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitApply(Gen.java:1929)
	at org.eclipse.jdt.internal.javac.ProceedOnErrorGen.visitApply(ProceedOnErrorGen.java:100)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1857)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:859)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitSelect(Gen.java:2390)
	at org.eclipse.jdt.internal.javac.ProceedOnErrorGen.visitSelect(ProceedOnErrorGen.java:109)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2570)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:859)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitApply(Gen.java:1929)
	at org.eclipse.jdt.internal.javac.ProceedOnErrorGen.visitApply(ProceedOnErrorGen.java:100)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1857)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:859)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genArgs(Gen.java:884)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitApply(Gen.java:1934)
	at org.eclipse.jdt.internal.javac.ProceedOnErrorGen.visitApply(ProceedOnErrorGen.java:100)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1857)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:859)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitExec(Gen.java:1802)
	at org.eclipse.jdt.internal.javac.ProceedOnErrorGen.visitExec(ProceedOnErrorGen.java:118)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1644)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:588)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:623)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:609)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStats(Gen.java:660)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.internalVisitBlock(Gen.java:1121)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitBlock(Gen.java:1085)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1133)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:588)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:623)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:609)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitIf(Gen.java:1776)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCIf.accept(JCTree.java:1613)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:588)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:623)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:609)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStats(Gen.java:660)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.internalVisitBlock(Gen.java:1121)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitBlock(Gen.java:1085)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1133)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:588)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:623)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genMethod(Gen.java:949)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitMethodDef(Gen.java:912)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:957)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:588)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genClass(Gen.java:2494)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:770)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1700)
	at org.eclipse.jdt.internal.javac.JavacCompiler$2.generate(JavacCompiler.java:156)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1668)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:977)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:897)
	at org.eclipse.jdt.internal.javac.JavacCompiler.compile(JavacCompiler.java:184)
	at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:441)
	at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.compile(BatchImageBuilder.java:250)
	at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:372)
	at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:118)
	at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:314)
	at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:226)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:1077)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:296)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:352)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:441)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:444)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:555)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:503)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:585)
	at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:207)
	at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:300)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

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

No branches or pull requests

2 participants