redhat-developer / redhat-developer/vscode-java

Java compiler problem with enums using windows1252 encoding

Open
#3,060 14 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
2.3k
Forks
546
Avg merge
20h 1m
Merged PRs (30d)
11

Description

So I'm trying to migrate from eclipse to vs code, all my projects are usually created using windows1252 for java files and utf8 for build/html/xhtml files, but when I try to run some projects that have special characters on enum names the compiler reports Syntax error for every single one of them, but when I open the files all the error messages disappear, if I close the file they return.

erro1

workspace

Workspace Settings
"settings": {
	"files.autoGuessEncoding": true,
	"java.configuration.updateBuildConfiguration": "automatic",
	"explorer.autoReveal": false
	"[java]": {
		"files.encoding": "windows1252"
	}
}
Preferences Settings
"java.jdt.ls.vmargs": "-Dfile.encoding=windows1252 -XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx1G -Xms100m -javaagent:\"c:\\Users\\berna\\.vscode\\extensions\\gabrielbb.vscode-lombok-1.0.1\\server\\lombok.jar\"",
"rsp-ui.rsp.java.home": "C:\\R2DA\\java\\jdk-11.0.10",
"[java]": {
	"files.encoding": "windows1252"
},
"files.encoding": "windows1252",
"sonarlint.ls.javaHome": "C:\\R2DA\\java\\jdk-11.0.10",
"spring-boot.ls.java.home": "C:\\Program Files\\Java\\jdk-17",
"java.import.gradle.java.home": "C:\\R2DA\\java\\jdk-11.0.10",
"java.project.encoding": "setDefault",
"java.jdt.ls.java.home": "C:\\Program Files\\Java\\jdk-17",
"java.configuration.runtimes": [
	{
		"name": "JavaSE-11",
		"path": "C:\\R2DA\\java\\jdk-11.0.10",
		"default": true,
	}
],
"spring-boot.ls.java.vmargs": [
	"-Dfile.encoding=windows1252"
],
"java.debug.settings.vmArgs": "-Dfile.encoding=windows1252",
Spring Dashboard Application Start Log
PS C:\R2DA\recivil\api-sistema-registro>  & 'C:\R2DA\java\jdk-11.0.10\bin\java.exe' '@C:\Users\berna\AppData\Local\Temp\cp_2u4mmuey7f1wwsl3uwa1ds5ug.argfile' 'api.sistema.registro.ApiSistemaRegistroApplication'
...
nested exception is java.lang.IllegalArgumentException: api.entidade.sistema.registro.enums.EnumPermissoes is not an enum type
        at api.sistema.registro.ApiSistemaRegistroApplication.main(ApiSistemaRegistroApplication.java:12) ~[main/:na]
Caused by: java.lang.IllegalArgumentException: api.entidade.sistema.registro.enums.EnumPermissoes is not an enum type
        at java.base/java.lang.Class.enumConstantDirectory(Class.java:3578) ~[na:na]
        at java.base/java.lang.Enum.valueOf(Enum.java:234) ~[na:na]
        at org.springframework.core.type.classreading.MergedAnnotationReadingVisitor.visitEnum(MergedAnnotationReadingVisitor.java:105) ~[spring-core-5.2.12.RELEASE.jar:5.2.12.RELEASE]
        at org.springframework.core.type.classreading.MergedAnnotationReadingVisitor$ArrayVisitor.visitEnum(MergedAnnotationReadingVisitor.java:171) ~[spring-core-5.2.12.RELEASE.jar:5.2.12.RELEASE]
        at org.springframework.asm.ClassReader.readElementValue(ClassReader.java:3056) ~[spring-core-5.2.12.RELEASE.jar:5.2.12.RELEASE]
        at org.springframework.asm.ClassReader.readElementValues(ClassReader.java:2981) ~[spring-core-5.2.12.RELEASE.jar:5.2.12.RELEASE]
        at org.springframework.asm.ClassReader.readElementValue(ClassReader.java:3155) ~[spring-core-5.2.12.RELEASE.jar:5.2.12.RELEASE]
        at org.springframework.asm.ClassReader.readElementValues(ClassReader.java:2975) ~[spring-core-5.2.12.RELEASE.jar:5.2.12.RELEASE]
        at org.springframework.asm.ClassReader.readMethod(ClassReader.java:1393) ~[spring-core-5.2.12.RELEASE.jar:5.2.12.RELEASE]
        at org.springframework.asm.ClassReader.accept(ClassReader.java:718) ~[spring-core-5.2.12.RELEASE.jar:5.2.12.RELEASE]
        at org.springframework.asm.ClassReader.accept(ClassReader.java:401) ~[spring-core-5.2.12.RELEASE.jar:5.2.12.RELEASE]
        at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:49) ~[spring-core-5.2.12.RELEASE.jar:5.2.12.RELEASE]
        at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:103) ~[spring-core-5.2.12.RELEASE.jar:5.2.12.RELEASE]
        at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:123) ~[spring-core-5.2.12.RELEASE.jar:5.2.12.RELEASE]
        at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.scanCandidateComponents(ClassPathScanningCandidateComponentProvider.java:429) ~[spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]
        ... 21 common frames omitted
Environment
  • Operating System: Windows 11 22H2
  • JDK version: 17.0.6 and 11.0.10
  • Visual Studio Code version: 1.77.2
  • Java extension version: Project Manager for Java v0.21.2 Debugger for Java v0.49.1 | Language Support for Java(TM) by Red Hat v1.16.0
Project Settings
  • Gradle 6.3
  • Java 11
  • Spring Boot 2.3.8.RELEASE
Steps To Reproduce
  1. Create a enum using windows1252 encoding and characters like ç ã é ú...
  2. Close the file and reload the project

Sample project for testing:
https://github.com/bernardomoraisbh/api-test

VS Code redhat.java/jdt_ws/.metadata/.log file:

https://pastebin.pl/view/e222cc93

Current Result

Compiler not working properly and error when running my spring projects over the Spring Dashboard Extension.

Expected Result

No compile errors and projects inside my workspace should be compiled with windows1252 encoding.

Additional Informations

I tried using the "spring-boot.ls.java.vmargs" settings for passing the encoding arg for the Spring Boot Dashboard extension, but I don't think it's working properly, since when I try to run the application over the dashboard I got only this args " & 'C:\R2DA\java\jdk-11.0.10\bin\java.exe' '@C:\Users\berna\AppData\Local\Temp\cp_2u4mmuey7f1wwsl3uwa1ds5ug.argfile' 'api.sistema.registro.ApiSistemaRegistroApplication'" and as soon as the application fails to start the file cp_2u4mmuey7f1wwsl3uwa1ds5ug.argfile is erased from the file system.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked api-test sample project and reproduce the issue using the listed Windows, JDK, Gradle, and VS Code settings. Read the redhat.java/jdt_ws/.metadata/.log output and compare the project encoding with the Spring Dashboard launch argfile. Done means the sample project compiles and starts with windows1252-encoded Java enums after the files are closed.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, typescript, vscode
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.