Skip to content

Commit f33d014

Browse files
authored
Merge pull request #1677 from guwirth/fix-quality-gate
Fix quality gate isssues
2 parents 43b1e0b + b98de0e commit f33d014

File tree

10 files changed

+37
-37
lines changed

10 files changed

+37
-37
lines changed

cxx-checks/src/main/java/org/sonar/cxx/checks/ReservedNamesCheck.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ public class ReservedNamesCheck extends SquidCheck<Grammar> implements CxxCharse
6161
@Override
6262
public void visitFile(AstNode astNode) {
6363

64-
try {
65-
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
66-
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(getContext().getFile()), charset));
64+
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
65+
try (BufferedReader br = new BufferedReader(
66+
new InputStreamReader(new FileInputStream(getContext().getFile()), charset))) {
6767
String line;
6868
int nr = 0;
6969

cxx-checks/src/main/java/org/sonar/cxx/checks/UseCorrectIncludeCheck.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ public class UseCorrectIncludeCheck extends SquidCheck<Grammar> implements CxxCh
5757

5858
@Override
5959
public void visitFile(AstNode astNode) {
60-
try {
61-
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
62-
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(getContext().getFile()), charset));
60+
61+
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
62+
try (BufferedReader br = new BufferedReader(
63+
new InputStreamReader(new FileInputStream(getContext().getFile()), charset))) {
6364
String line;
6465
int nr = 0;
6566

cxx-checks/src/main/java/org/sonar/cxx/checks/file/TabCharacterCheck.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ public void setCharset(Charset charset) {
6868

6969
@Override
7070
public void visitFile(AstNode astNode) {
71-
try {
72-
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
73-
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(getContext().getFile()), charset));
71+
72+
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
73+
try (BufferedReader br = new BufferedReader(
74+
new InputStreamReader(new FileInputStream(getContext().getFile()), charset))) {
7475
String line;
7576
int nr = 0;
7677

cxx-checks/src/main/java/org/sonar/cxx/checks/metrics/TooLongLineCheck.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ public void setCharset(Charset charset) {
7979

8080
@Override
8181
public void visitFile(AstNode astNode) {
82-
try {
83-
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
84-
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(getContext().getFile()), charset));
82+
83+
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
84+
try (BufferedReader br = new BufferedReader(
85+
new InputStreamReader(new FileInputStream(getContext().getFile()), charset))) {
8586
String line;
8687
int nr = 0;
8788

cxx-checks/src/main/java/org/sonar/cxx/checks/regex/FileHeaderCheck.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ public void init() {
104104

105105
@Override
106106
public void visitFile(AstNode astNode) {
107-
try {
108-
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
109-
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(getContext().getFile()), charset));
107+
108+
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
109+
try (BufferedReader br = new BufferedReader(
110+
new InputStreamReader(new FileInputStream(getContext().getFile()), charset))) {
110111

111112
if (isRegularExpression) {
112113
String fileContent = br.lines().collect(Collectors.joining(System.lineSeparator()));

cxx-checks/src/main/java/org/sonar/cxx/checks/regex/FileRegularExpressionCheck.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,11 @@ public void setCharset(Charset charset) {
122122

123123
@Override
124124
public void visitFile(AstNode fileNode) {
125-
try {
126-
if (!compare(invertFilePattern, matchFile())) {
127-
return;
128-
}
129-
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
130-
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(getContext().getFile()), charset));
125+
if (!compare(invertFilePattern, matchFile())) {
126+
return;
127+
}
128+
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
129+
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(getContext().getFile()), charset))) {
131130
final String fileContent = br.lines().collect(Collectors.joining(System.lineSeparator()));
132131
Matcher matcher = pattern.matcher(fileContent);
133132
if (compare(invertRegularExpression, matcher.find())) {

cxx-checks/src/main/java/org/sonar/cxx/checks/regex/LineRegularExpressionCheck.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ public void setCharset(Charset charset) {
122122
@Override
123123
public void visitFile(AstNode fileNode) {
124124
if (compare(invertFilePattern, matchFile())) {
125-
try {
126-
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
127-
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(getContext().getFile()), charset));
125+
// use onMalformedInput(CodingErrorAction.REPLACE) / onUnmappableCharacter(CodingErrorAction.REPLACE)
126+
try (BufferedReader br = new BufferedReader(
127+
new InputStreamReader(new FileInputStream(getContext().getFile()), charset))) {
128128
String line;
129129
int nr = 0;
130130

cxx-sensors/src/main/java/org/sonar/cxx/sensors/drmemory/DrMemoryParser.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ public static List<DrMemoryError> parse(File file, String charset) {
9292
public static List<String> getElements(File file, String charset) {
9393

9494
List<String> list = new ArrayList<>();
95-
try (InputStream input = java.nio.file.Files.newInputStream(file.toPath())) {
96-
BufferedReader br = new BufferedReader(new InputStreamReader(input, charset));
95+
try (BufferedReader br = new BufferedReader(
96+
new InputStreamReader(java.nio.file.Files.newInputStream(file.toPath()), charset))) {
9797
StringBuilder sb = new StringBuilder(4096);
9898
String line;
9999
int cnt = 0;
@@ -109,14 +109,12 @@ public static List<String> getElements(File file, String charset) {
109109
sb.append('\n');
110110
}
111111
}
112-
cnt++;
112+
++cnt;
113113
}
114114

115115
if (sb.length() > 0) {
116116
list.add(sb.toString());
117117
}
118-
119-
br.close();
120118
} catch (IOException e) {
121119
String msg = new StringBuilder(512).append("Cannot feed the data into sonar, details: '")
122120
.append(e)

cxx-squid/src/main/java/org/sonar/cxx/CxxVCppBuildLogParser.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ public void parseVCppLine(String line, String projectPath, String compilationFil
117117
*/
118118
public void parseVCppLog(File buildLog, String baseDir, String charsetName) {
119119
boolean detectedPlatform = false;
120-
try (InputStream input = java.nio.file.Files.newInputStream(buildLog.toPath())) {
121-
BufferedReader br = new BufferedReader(new InputStreamReader(input, charsetName));
120+
try (BufferedReader br = new BufferedReader(
121+
new InputStreamReader(java.nio.file.Files.newInputStream(buildLog.toPath()), charsetName))) {
122122
String line;
123123
if (LOG.isDebugEnabled()) {
124124
LOG.debug("build log parser baseDir='{}'", baseDir);
@@ -179,7 +179,6 @@ public void parseVCppLog(File buildLog, String baseDir, String charsetName) {
179179
}
180180
}
181181
}
182-
br.close();
183182
} catch (IOException ex) {
184183
LOG.error("Cannot parse build log", ex);
185184
}

sslr-cxx-toolkit/src/main/java/org/sonar/cxx/toolkit/CxxConfigurationModel.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,23 @@ public class CxxConfigurationModel extends AbstractConfigurationModel {
5959

6060
private final MapSettings settings = new MapSettings();
6161

62-
ConfigurationProperty charsetProperty = new ConfigurationProperty("Charset", CHARSET_PROPERTY_KEY,
62+
private final ConfigurationProperty charsetProperty = new ConfigurationProperty("Charset", CHARSET_PROPERTY_KEY,
6363
getPropertyOrDefaultValue(CHARSET_PROPERTY_KEY, "UTF-8"),
6464
Validators.charsetValidator());
6565

66-
ConfigurationProperty errorRecoveryEnabled = new ConfigurationProperty("Error Recovery", ERROR_RECOVERY_PROPERTY_KEY,
66+
private final ConfigurationProperty errorRecoveryEnabled = new ConfigurationProperty("Error Recovery", ERROR_RECOVERY_PROPERTY_KEY,
6767
getPropertyOrDefaultValue(ERROR_RECOVERY_PROPERTY_KEY, "false"),
6868
Validators.booleanValidator());
6969

70-
ConfigurationProperty defines = new ConfigurationProperty("Defines", DEFINES_PROPERTY_KEY
70+
private final ConfigurationProperty defines = new ConfigurationProperty("Defines", DEFINES_PROPERTY_KEY
7171
+ " (use \\n\\ as separator)",
7272
getPropertyOrDefaultValue(DEFINES_PROPERTY_KEY, ""));
7373

74-
ConfigurationProperty includeDirectories = new ConfigurationProperty("Include Directories",
74+
private final ConfigurationProperty includeDirectories = new ConfigurationProperty("Include Directories",
7575
INCLUDE_DIRECTORIES_PROPERTY_KEY + " (use , as separator)",
7676
getPropertyOrDefaultValue(INCLUDE_DIRECTORIES_PROPERTY_KEY, ""));
7777

78-
ConfigurationProperty forceIncludes = new ConfigurationProperty("Force Includes", FORCE_INCLUDES_PROPERTY_KEY
78+
private final ConfigurationProperty forceIncludes = new ConfigurationProperty("Force Includes", FORCE_INCLUDES_PROPERTY_KEY
7979
+ " (use , as separator)",
8080
getPropertyOrDefaultValue(FORCE_INCLUDES_PROPERTY_KEY, ""));
8181

0 commit comments

Comments
 (0)