redhat-developer / redhat-developer/vscode-java

Java compiler problem with enums using windows1252 encoding

未关闭
#3,060 14 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
TypeScript
星标
2.3k
派生
546
平均合并
20 小时 1 分钟
30 天内合并 PR
11

描述

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.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从链接的 api-test 示例项目开始,并使用列出的 Windows、JDK、Gradle 和 VS Code 设置复现该问题。读取 redhat.java/jdt_ws/.metadata/.log 的输出,并将项目编码与 Spring Dashboard 的启动 argfile 进行比较。在文件关闭后,示例项目能够使用以 windows1252 编码的 Java 枚举进行编译并启动,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
java, typescript, vscode
领域
tooling
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。