Skip to content

Commit dcc55c5

Browse files
committed
Enforce PMD UnnecessaryLocalBeforeReturn rule
1 parent e68f56e commit dcc55c5

23 files changed

Lines changed: 27 additions & 61 deletions

pmd-rules.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
<exclude name="ConfusingTernary" />
5656
<exclude name="FieldDeclarationsShouldBeAtStartOfClass" />
5757
<exclude name="PrematureDeclaration" />
58-
<exclude name="UnnecessaryLocalBeforeReturn" />
5958
<exclude name="BooleanGetMethodName" />
6059
</rule>
6160
<!-- <rule ref="category/java/design.xml"> <priority>4</priority> </rule>

src/sqlancer/LikeImplementationHelper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ public static boolean match(String str, String regex, int regexPosition, int str
4848

4949
private static char toUpper(char cur) {
5050
if (cur >= 'a' && cur <= 'z') {
51-
char c = (char) (cur + 'A' - 'a');
52-
return c;
51+
return (char) (cur + 'A' - 'a');
5352
} else {
5453
return cur;
5554
}

src/sqlancer/Main.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,7 @@ private String getStackTrace(Throwable e1) {
200200
StringWriter sw = new StringWriter();
201201
PrintWriter pw = new PrintWriter(sw);
202202
e1.printStackTrace(pw);
203-
String stackTrace = "--" + sw.toString().replace("\n", "\n--");
204-
return stackTrace;
203+
return "--" + sw.toString().replace("\n", "\n--");
205204
}
206205

207206
private void printState(FileWriter writer, StateToReproduce state) {

src/sqlancer/Randomly.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ public static <T> List<T> extractNrRandomColumns(List<T> columns, int nr) {
187187

188188
public static int smallNumber() {
189189
// no need to cache for small numbers
190-
int val = (int) (Math.abs(ThreadLocalRandom.current().nextGaussian()) * 2);
191-
return val;
190+
return (int) (Math.abs(ThreadLocalRandom.current().nextGaussian()) * 2);
192191
}
193192

194193
public static boolean getBoolean() {

src/sqlancer/cockroachdb/ast/CockroachDBFunction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,7 @@ public CockroachDBFunctionCall getCall(CockroachDBCompositeDataType returnType,
177177
int depth) {
178178
CockroachDBDataType[] argumentTypes2 = getArgumentTypes(returnType);
179179
List<CockroachDBExpression> arguments = getArgumentsForReturnType(gen, depth, argumentTypes2, returnType);
180-
CockroachDBFunctionCall call = new CockroachDBFunctionCall(this, arguments);
181-
return call;
180+
return new CockroachDBFunctionCall(this, arguments);
182181
}
183182

184183
List<CockroachDBExpression> getArgumentsForReturnType(CockroachDBExpressionGenerator gen, int depth,

src/sqlancer/cockroachdb/gen/CockroachDBCreateStatisticsGenerator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@ public static Query create(CockroachDBGlobalState globalState) {
2424
sb.append(" FROM ");
2525
sb.append(randomTable.getName());
2626

27-
Query q = new QueryAdapter(sb.toString(),
27+
return new QueryAdapter(sb.toString(),
2828
Arrays.asList("current transaction is aborted, commands ignored until end of transaction block",
2929
"ERROR: unable to encode table key: *tree.DArray" /*
3030
* https://github.com/cockroachdb/cockroach/
3131
* issues/46964
3232
*/, "overflow during Encode"));
33-
return q;
3433
}
3534

3635
}

src/sqlancer/cockroachdb/gen/CockroachDBExpressionGenerator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,7 @@ public CockroachDBExpression generateConstant(CockroachDBCompositeDataType type)
282282
return CockroachDBConstant.createBooleanConstant(Randomly.getBoolean());
283283
case STRING:
284284
case BYTES: // TODO: also generate byte constants
285-
CockroachDBExpression strConst = getStringConstant();
286-
return strConst;
285+
return getStringConstant();
287286
case FLOAT:
288287
return CockroachDBConstant.createFloatConstant(globalState.getRandomly().getDouble());
289288
case BIT:

src/sqlancer/cockroachdb/gen/CockroachDBSetClusterSettingGenerator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ public static Query create(CockroachDBGlobalState globalState) {
5959
errors.add("setting updated but timed out waiting to read new value");
6060

6161
CockroachDBErrors.addTransactionErrors(errors);
62-
Query q = new QueryAdapter(sb.toString(), errors);
63-
return q;
62+
return new QueryAdapter(sb.toString(), errors);
6463
}
6564

6665
}

src/sqlancer/cockroachdb/gen/CockroachDBSetSessionGenerator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ public static Query create(CockroachDBGlobalState globalState) {
5555
sb.append(s.f.apply(globalState));
5656
Set<String> errors = new HashSet<>();
5757
CockroachDBErrors.addTransactionErrors(errors);
58-
Query q = new QueryAdapter(sb.toString(), errors);
59-
return q;
58+
return new QueryAdapter(sb.toString(), errors);
6059
}
6160

6261
}

src/sqlancer/cockroachdb/gen/CockroachDBTruncateGenerator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ public static Query truncate(CockroachDBGlobalState globalState) {
4141
sb.append(" ");
4242
sb.append(Randomly.fromOptions("CASCADE", "RESTRICT"));
4343
}
44-
Query q = new QueryAdapter(sb.toString(), errors);
45-
return q;
44+
return new QueryAdapter(sb.toString(), errors);
4645
}
4746

4847
}

0 commit comments

Comments
 (0)