Use try-with-resources; other warnings fixed

GitOrigin-RevId: 57e9bbb62af11b0629f9d02534b07e7a921c55af
This commit is contained in:
Tagir Valeev
2022-02-08 11:33:36 +07:00
committed by intellij-monorepo-bot
parent b993d39371
commit 3df143dfe6
31 changed files with 190 additions and 423 deletions

View File

@@ -112,22 +112,17 @@ public class PythonFileType extends LanguageFileType {
if (content == null || content.length() == 0) {
return null;
}
try {
final BufferedReader reader = new BufferedReader(new CharSequenceReader(content));
try {
for (int i = 0; i < MAX_CHARSET_ENCODING_LINE; i++) {
final String line = reader.readLine();
if (line == null) {
return null;
}
final Matcher matcher = ENCODING_PATTERN.matcher(line);
if (matcher.find()) {
final String charset = matcher.group(1);
return normalizeCharset(charset);
}
try (BufferedReader reader = new BufferedReader(new CharSequenceReader(content))) {
for (int i = 0; i < MAX_CHARSET_ENCODING_LINE; i++) {
final String line = reader.readLine();
if (line == null) {
return null;
}
final Matcher matcher = ENCODING_PATTERN.matcher(line);
if (matcher.find()) {
final String charset = matcher.group(1);
return normalizeCharset(charset);
}
} finally {
reader.close();
}
}
catch (IOException ignored) {