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

Support for JDK 14 for Gradle projects #1338

Closed
manastalukdar opened this issue Mar 21, 2020 · 10 comments
Closed

Support for JDK 14 for Gradle projects #1338

manastalukdar opened this issue Mar 21, 2020 · 10 comments

Comments

@manastalukdar
Copy link

manastalukdar commented Mar 21, 2020

Please add support for JDK 14

Environment
  • Operating System: Windows 10 x64
  • JDK version: 14
  • Visual Studio Code version: 1.44.0-insider
  • Java extension version: 0.58.0

Repro project: https://github.com/manastalukdar/dummy-java (gradle based)


Update: https://twitter.com/VSCodeJava/status/1241478764091133952

@snjeza
Copy link
Contributor

snjeza commented Mar 21, 2020

@manastalukdar You may want to take a look at #1302 and eclipse-jdtls/eclipse.jdt.ls#1360

@gabrielbcn
Copy link

Please...

Right now...

/Library/Java/JavaVirtualMachines/openjdk-14.jdk/Contents/Home/bin/java --enable-preview -Dfile.encoding=UTF-8 -cp "/Users/gabriel/Library/Application Support/Code/User/workspaceStorage/2cfe7776ea6b5be44832e599c44a91d4/redhat.java/jdt_ws/EvolveN_64cb39b9/bin" ConnectN
Error: LinkageError occurred while loading main class ConnectN
java.lang.UnsupportedClassVersionError: ConnectN (class file version 57.65535) was compiled with preview features that are unsupported. This version of the Java Runtime only recognizes preview features for class file version 58.65535

So the javac and java versions are not aligned (I only have JDK 14 and bothered to check that 13 wasn't there anymore): compiles with v13 and runs with v14 for some reason.

If we could disable preview features when compiling, that would be a workaround

Thanks

@snjeza
Copy link
Contributor

snjeza commented Mar 22, 2020

@manastalukdar you can try to add the following property:

org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled

to <your_project>/.settings/org.eclipse.jdt.core.prefs

@fbricon
Copy link
Collaborator

fbricon commented Mar 23, 2020

The server fix applies the Java 14 patch on JDT 4.15 (See https://marketplace.eclipse.org/content/java-14-support-eclipse-2020-03-415)

Known Issues:

  • Try statement inside switch expressions yielding values are known to have stack map verification errors. More details at https://bugs.eclipse.org/545567
  • The compiler does not yet support pattern matching instanceof expressions as part of field declaration, in other words, outside method bodies. More on this can be found on https://bugs.eclipse.org/531715

@fbricon
Copy link
Collaborator

fbricon commented Mar 23, 2020

@manastalukdar sorry but seems like Java 14 support for Gradle is not there yet. Your example uses compileTestJava, which is ignored by Buildship, because Eclipse cannot use different compiler settings for main and test code, nothing we can do about it.
So I tried with compileJava instead, but I found that sourceCompatibility/targetCompatibility in compileJava block are ignored in buildship. I then tried to move the sourceCompatibility/targetCompatibility settings at the root of the build file, the JRE is now properly set but Buildship barfs with "Project configurator 'org.eclipse.buildship.configurators.base' failed to configure project 'dummy-java'". Turns out this is caused by:

java.lang.IllegalArgumentException: Cannot convert string value 'VERSION_14' to an enum value of type 'org.gradle.api.JavaVersion' (valid case insensitive values: VERSION_1_1, VERSION_1_2, VERSION_1_3, VERSION_1_4, VERSION_1_5, VERSION_1_6, VERSION_1_7, VERSION_1_8, VERSION_1_9, VERSION_1_10, VERSION_11, VERSION_12, VERSION_13, VERSION_HIGHER).

This might be caused by Buildship embedding its own version of the gradle api, as opposed to the version used by the gradle wrapper, but I'm not sure. @donat?

@fbricon fbricon changed the title Support for JDK 14 Support for JDK 14 for Gradle projects Mar 23, 2020
@donat
Copy link

donat commented Mar 24, 2020

This might be caused by Buildship embedding its own version of the gradle api

Exactly. We'll fix this shorly. Check eclipse/buildship#979 for the details.

@fbricon fbricon added this to the End March 2020 milestone Mar 31, 2020
@fbricon
Copy link
Collaborator

fbricon commented Mar 31, 2020

Example of build.gradle file supporting Java 14 preview features. Requires Gradle 6.3 and needs to manually invoke ./gradlew eclipse, so the generated eclipse JDT config files can be used by vscode-java:

apply plugin: 'java'
apply plugin: 'eclipse'

sourceCompatibility = JavaVersion.VERSION_14
targetCompatibility = JavaVersion.VERSION_14

compileJava {
    options.compilerArgs += ["--enable-preview"]
}
compileTestJava {
    options.compilerArgs += ["--enable-preview"]
}
//Buildship doesn't use that hook (https://discuss.gradle.org/t/when-does-buildship-eclipse-customization-run/20781/2)
//you need to run `gradle eclipse` separately
eclipse.jdt.file.withProperties { props ->
    props['org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures']= 'enabled'
    props['org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures']= 'ignore'
}

test {
    jvmArgs '--enable-preview'
}

@fbricon fbricon closed this as completed Mar 31, 2020
@manastalukdar
Copy link
Author

Does not work. Following exception from Language Support for Java:

[Error - 12:07:52 AM] Request textDocument/codeAction failed.
  Message: Internal error.
  Code: -32603 
java.util.concurrent.CompletionException: java.lang.NullPointerException
	at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:314)
	at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:319)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:645)
	at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:479)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1016)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1665)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1598)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:177)
Caused by: java.lang.NullPointerException
	at org.eclipse.jdt.internal.corext.codemanipulation.tostringgeneration.AbstractToStringGenerator.createMethodComment(AbstractToStringGenerator.java:232)
	at org.eclipse.jdt.internal.corext.codemanipulation.tostringgeneration.AbstractToStringGenerator.complete(AbstractToStringGenerator.java:489)
	at org.eclipse.jdt.internal.corext.codemanipulation.tostringgeneration.StringConcatenationGenerator.complete(StringConcatenationGenerator.java:93)
	at org.eclipse.jdt.internal.corext.codemanipulation.tostringgeneration.AbstractToStringGenerator.generateToStringMethod(AbstractToStringGenerator.java:207)
	at org.eclipse.jdt.internal.corext.codemanipulation.tostringgeneration.GenerateToStringOperation.run(GenerateToStringOperation.java:102)
	at org.eclipse.jdt.ls.core.internal.handlers.GenerateToStringHandler.generateToString(GenerateToStringHandler.java:120)
	at org.eclipse.jdt.ls.core.internal.handlers.GenerateToStringHandler.generateToString(GenerateToStringHandler.java:105)
	at org.eclipse.jdt.ls.core.internal.text.correction.SourceAssistProcessor.getSourceActionCommands(SourceAssistProcessor.java:135)
	at org.eclipse.jdt.ls.core.internal.handlers.CodeActionHandler.getCodeActionCommands(CodeActionHandler.java:151)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$14(JDTLanguageServer.java:628)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$48(JDTLanguageServer.java:977)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:642)
	... 6 more

[Error - 12:07:52 AM] Request textDocument/codeAction failed.
  Message: Internal error.
  Code: -32603 
java.util.concurrent.CompletionException: java.lang.NullPointerException
	at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:314)
	at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:319)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:645)
	at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:479)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1016)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1665)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1598)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:177)
Caused by: java.lang.NullPointerException
	at org.eclipse.jdt.internal.corext.codemanipulation.tostringgeneration.AbstractToStringGenerator.createMethodComment(AbstractToStringGenerator.java:232)
	at org.eclipse.jdt.internal.corext.codemanipulation.tostringgeneration.AbstractToStringGenerator.complete(AbstractToStringGenerator.java:489)
	at org.eclipse.jdt.internal.corext.codemanipulation.tostringgeneration.StringConcatenationGenerator.complete(StringConcatenationGenerator.java:93)
	at org.eclipse.jdt.internal.corext.codemanipulation.tostringgeneration.AbstractToStringGenerator.generateToStringMethod(AbstractToStringGenerator.java:207)
	at org.eclipse.jdt.internal.corext.codemanipulation.tostringgeneration.GenerateToStringOperation.run(GenerateToStringOperation.java:102)
	at org.eclipse.jdt.ls.core.internal.handlers.GenerateToStringHandler.generateToString(GenerateToStringHandler.java:120)
	at org.eclipse.jdt.ls.core.internal.handlers.GenerateToStringHandler.generateToString(GenerateToStringHandler.java:105)
	at org.eclipse.jdt.ls.core.internal.text.correction.SourceAssistProcessor.getSourceActionCommands(SourceAssistProcessor.java:135)
	at org.eclipse.jdt.ls.core.internal.handlers.CodeActionHandler.getCodeActionCommands(CodeActionHandler.java:151)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$14(JDTLanguageServer.java:628)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$48(JDTLanguageServer.java:977)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:642)
	... 6 more

@fbricon
Copy link
Collaborator

fbricon commented Apr 1, 2020

@manastalukdar this is another issue. Please open a different ticket for that, with exact steps to reproduce (adding a sample project would help a lot).

@manastalukdar
Copy link
Author

@fbricon NPE issue is resolved with latest extension. All good now. Thanks for your help.

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

No branches or pull requests

5 participants