Skip to content

Commit e39953a

Browse files
committed
Defensively copy all arrays passed to constructors and enforce a PMD rule
1 parent 77afe49 commit e39953a

20 files changed

Lines changed: 24 additions & 25 deletions

configs/pmd-rules.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
<exclude name="AvoidReassigningParameters" />
2121
<exclude name="PositionLiteralsFirstInComparisons" />
2222
<exclude name="ForLoopCanBeForeach" />
23-
<exclude name="ArrayIsStoredDirectly" />
2423
<exclude name="MethodReturnsInternalArray" />
2524
<exclude name="CheckResultSet" />
2625
<exclude name="UseVarargs" />
@@ -31,7 +30,7 @@
3130
</rule>
3231

3332
<rule ref="category/java/codestyle.xml">
34-
<priority>2</priority>
33+
<priority>1</priority>
3534
<exclude name="MethodArgumentCouldBeFinal" />
3635
<exclude name="LocalVariableCouldBeFinal" />
3736
<exclude name="ShortVariable" />

src/sqlancer/StatementExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public interface ActionMapper<T, A> {
2323

2424
public StatementExecutor(G globalState, A[] actions, ActionMapper<G, A> mapping, AfterQueryAction queryConsumer) {
2525
this.globalState = globalState;
26-
this.actions = actions;
26+
this.actions = actions.clone();
2727
this.mapping = mapping;
2828
this.queryConsumer = queryConsumer;
2929
}

src/sqlancer/cockroachdb/ast/CockroachDBAggregate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static List<CockroachDBAggregateFunction> getAggregates(CockroachDBDataTy
7575

7676
//
7777
CockroachDBAggregateFunction(CockroachDBDataType... supportedReturnTypes) {
78-
this.supportedReturnTypes = supportedReturnTypes;
78+
this.supportedReturnTypes = supportedReturnTypes.clone();
7979
}
8080

8181
public static CockroachDBAggregateFunction getRandom() {

src/sqlancer/cockroachdb/ast/CockroachDBFunction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public CockroachDBDataType[] getArgumentTypes(CockroachDBCompositeDataType retur
145145

146146
CockroachDBFunction(CockroachDBDataType returnType, CockroachDBDataType... argumentTypes) {
147147
this.returnType = returnType;
148-
this.argumentTypes = argumentTypes;
148+
this.argumentTypes = argumentTypes.clone();
149149
this.functionName = toString();
150150
}
151151

@@ -162,7 +162,7 @@ public String getFunctionName() {
162162
CockroachDBFunction(String functionName, CockroachDBDataType returnType, CockroachDBDataType... argumentTypes) {
163163
this.functionName = functionName;
164164
this.returnType = returnType;
165-
this.argumentTypes = argumentTypes;
165+
this.argumentTypes = argumentTypes.clone();
166166
}
167167

168168
public boolean isCompatibleWithReturnType(CockroachDBCompositeDataType returnType) {

src/sqlancer/mariadb/gen/MariaDBSetGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private enum Action {
125125
}
126126
this.name = name;
127127
this.prod = prod;
128-
this.scopes = scopes;
128+
this.scopes = scopes.clone();
129129
}
130130

131131
private static String getOptimizerSwitchConfiguration(Randomly r) {

src/sqlancer/mysql/ast/MySQLBinaryLogicalOperation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public MySQLConstant apply(MySQLConstant left, MySQLConstant right) {
6060
private final String[] textRepresentations;
6161

6262
MySQLBinaryLogicalOperator(String... textRepresentations) {
63-
this.textRepresentations = textRepresentations;
63+
this.textRepresentations = textRepresentations.clone();
6464
}
6565

6666
String getTextRepresentation() {

src/sqlancer/mysql/ast/MySQLComputableFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class MySQLComputableFunction implements MySQLExpression {
1414

1515
public MySQLComputableFunction(MySQLFunction func, MySQLExpression... args) {
1616
this.func = func;
17-
this.args = args;
17+
this.args = args.clone();
1818
}
1919

2020
public MySQLFunction getFunction() {

src/sqlancer/mysql/ast/MySQLUnaryPrefixOperation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public MySQLConstant applyNotNull(MySQLConstant expr) {
4343
private String[] textRepresentations;
4444

4545
MySQLUnaryPrefixOperator(String... textRepresentations) {
46-
this.textRepresentations = textRepresentations;
46+
this.textRepresentations = textRepresentations.clone();
4747
}
4848

4949
public abstract MySQLConstant applyNotNull(MySQLConstant expr);

src/sqlancer/mysql/gen/MySQLAlterTable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ PACK_KEYS, RENAME("doesn't exist", "already exists"), /* WITH_WITHOUT_VALIDATION
5454
private String[] potentialErrors;
5555

5656
Action(String... couldCauseErrors) {
57-
this.potentialErrors = couldCauseErrors;
57+
this.potentialErrors = couldCauseErrors.clone();
5858
}
5959

6060
}

src/sqlancer/mysql/gen/MySQLSetGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private enum Action {
207207
}
208208
this.name = name;
209209
this.prod = prod;
210-
this.scopes = scopes;
210+
this.scopes = scopes.clone();
211211
}
212212

213213
/**

0 commit comments

Comments
 (0)