-
Notifications
You must be signed in to change notification settings - Fork 126
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
Do not throw exceptions for unsupported charsets #827
base: master
Are you sure you want to change the base?
Do not throw exceptions for unsupported charsets #827
Conversation
A character set in an XML file which is not supported by the JVM by default should not terminate the initialization of the file system.
Hi @oleosterhagen, thank you for opening the PR. We will discuss it internally before we proceed on this. Have you tested your changes with files that have a unsupported charset? What happens if you now analyze such a file with a unsupported charset? What happens if you do a full project analysis? What happens in general when you "use" it. I'd like to be sure that when these changes are added, no unforeseen other errors are popping up along the road. |
Hi @thahnen, thank you for your reply and questions. In my fix I chose the same fallback value Lines 89 to 92 in 42cbbaf
Normally the default charset will be UTF-8. Later when analyzing the file, the content will be read with this charset (see: https://github.com/SonarSource/sonarlint-core/blob/83448ab386d7fea28960f8ddea2d2690f65e62b7/backend/core/src/main/java/org/sonarsource/sonarlint/core/fs/ClientFile.java#L115-L120): var charsetToUse = charset != null ? charset : Charset.defaultCharset();
try {
return Files.readString(fsPath, charsetToUse);
} catch (IOException e) {
throw new IllegalStateException("Unable to read file " + fsPath + "content with charset " + charsetToUse, e);
} When the analyzed file happens to contain an illegal UTF-8 sequence like 0xff, then the exception handler will be executed. When analyzing a single file only an error but no stacktrace will be shown in the console:
When analyzing the whole project a stacktrace is displayed:
There may be other ways or places to skip files with unsupported charsets, e.g. catching the Lines 88 to 91 in 42cbbaf
What do you suggest? |
When there is an XML file in the workspace with a character set which is not supported by the JVM by default, the following exception will be thrown and the initialization of the filesystem is terminated.
Later during the analysis, some files may not be found, because the above exception has stopped the initialization of the filesystem.