Skip to content

Commit 4664001

Browse files
authored
Refactor several classes (#752)
* Refactor Several classes Signed-off-by: Krishan Chavinda <90906063+krishan30@users.noreply.github.com> * mvn formatter:format Signed-off-by: Krishan Chavinda <90906063+krishan30@users.noreply.github.com> * Checkstyle Error fix Signed-off-by: Krishan Chavinda <90906063+krishan30@users.noreply.github.com> --------- Signed-off-by: Krishan Chavinda <90906063+krishan30@users.noreply.github.com>
1 parent 85bea19 commit 4664001

18 files changed

+32
-34
lines changed

src/sqlancer/ProviderAdapter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public abstract class ProviderAdapter<G extends GlobalState<O, ? extends Abstrac
2626
int currentSelectCounts;
2727
int currentMutationOperator = -1;
2828

29-
public ProviderAdapter(Class<G> globalClass, Class<O> optionClass) {
29+
protected ProviderAdapter(Class<G> globalClass, Class<O> optionClass) {
3030
this.globalClass = globalClass;
3131
this.optionClass = optionClass;
3232
}
@@ -85,7 +85,7 @@ protected TestOracle<G> getTestOracle(G globalState) throws Exception {
8585
List<? extends OracleFactory<G>> testOracleFactory = globalState.getDbmsSpecificOptions()
8686
.getTestOracleFactory();
8787
boolean testOracleRequiresMoreThanZeroRows = testOracleFactory.stream()
88-
.anyMatch(p -> p.requiresAllTablesToContainRows());
88+
.anyMatch(OracleFactory::requiresAllTablesToContainRows);
8989
boolean userRequiresMoreThanZeroRows = globalState.getOptions().testOnlyWithMoreThanZeroRows();
9090
boolean checkZeroRows = testOracleRequiresMoreThanZeroRows || userRequiresMoreThanZeroRows;
9191
if (checkZeroRows && globalState.getSchema().containsTableWithZeroRows(globalState)) {
@@ -98,7 +98,7 @@ protected TestOracle<G> getTestOracle(G globalState) throws Exception {
9898
if (testOracleFactory.size() == 1) {
9999
return testOracleFactory.get(0).create(globalState);
100100
} else {
101-
return new CompositeTestOracle<G>(testOracleFactory.stream().map(o -> {
101+
return new CompositeTestOracle<>(testOracleFactory.stream().map(o -> {
102102
try {
103103
return o.create(globalState);
104104
} catch (Exception e1) {
@@ -170,7 +170,7 @@ private synchronized boolean mutateTables(G globalState) throws Exception {
170170
if (Randomly.getPercentage() < globalState.getOptions().getQPGProbability()) {
171171
selectedActionIndex = globalState.getRandomly().getInteger(0, weightedAverageReward.length);
172172
} else {
173-
selectedActionIndex = DBMSCommon.getMaxIndexInDoubleArrary(weightedAverageReward);
173+
selectedActionIndex = DBMSCommon.getMaxIndexInDoubleArray(weightedAverageReward);
174174
}
175175
int reward = 0;
176176

src/sqlancer/Randomly.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.math.BigDecimal;
44
import java.util.ArrayList;
55
import java.util.Arrays;
6+
import java.util.Collections;
67
import java.util.List;
78
import java.util.Random;
89
import java.util.function.Supplier;
@@ -133,17 +134,12 @@ public static <T> List<T> subset(List<T> columns) {
133134

134135
public static <T> List<T> subset(int nr, @SuppressWarnings("unchecked") T... values) {
135136
List<T> list = new ArrayList<>();
136-
for (T val : values) {
137-
list.add(val);
138-
}
137+
Collections.addAll(list, values);
139138
return extractNrRandomColumns(list, nr);
140139
}
141140

142141
public static <T> List<T> subset(@SuppressWarnings("unchecked") T... values) {
143-
List<T> list = new ArrayList<>();
144-
for (T val : values) {
145-
list.add(val);
146-
}
142+
List<T> list = new ArrayList<>(Arrays.asList(values));
147143
return subset(list);
148144
}
149145

@@ -350,7 +346,6 @@ public long getNonZeroInteger() {
350346
do {
351347
value = getInteger();
352348
} while (value == 0);
353-
assert value != 0;
354349
addToCache(value);
355350
return value;
356351
}
@@ -425,7 +420,7 @@ public long getLong(long left, long right) {
425420
}
426421

427422
public BigDecimal getRandomBigDecimal() {
428-
return new BigDecimal(getThreadRandom().get().nextDouble());
423+
return BigDecimal.valueOf(getThreadRandom().get().nextDouble());
429424
}
430425

431426
public long getPositiveIntegerNotNull() {
@@ -494,7 +489,7 @@ private static long getNextLong(long lower, long upper) {
494489
if (lower == upper) {
495490
return lower;
496491
}
497-
return (long) (getThreadRandom().get().longs(lower, upper).findFirst().getAsLong());
492+
return getThreadRandom().get().longs(lower, upper).findFirst().getAsLong();
498493
}
499494

500495
private static int getNextInt(int lower, int upper) {

src/sqlancer/SQLProviderAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
public abstract class SQLProviderAdapter<G extends SQLGlobalState<O, ? extends AbstractSchema<G, ?>>, O extends DBMSSpecificOptions<? extends OracleFactory<G>>>
1212
extends ProviderAdapter<G, O, SQLConnection> {
13-
public SQLProviderAdapter(Class<G> globalClass, Class<O> optionClass) {
13+
protected SQLProviderAdapter(Class<G> globalClass, Class<O> optionClass) {
1414
super(globalClass, optionClass);
1515
}
1616

src/sqlancer/StateToReproduce.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ public List<Query<?>> getStatements() {
7070
return Collections.unmodifiableList(statements);
7171
}
7272

73+
/**
74+
* @deprecated
75+
*/
7376
@Deprecated
7477
public void commentStatements() {
7578
for (int i = 0; i < statements.size(); i++) {
@@ -100,7 +103,7 @@ public class OracleRunReproductionState implements Closeable {
100103

101104
private final List<Query<?>> statements = new ArrayList<>();
102105

103-
public boolean success;
106+
private boolean success;
104107

105108
public OracleRunReproductionState() {
106109
StateToReproduce.this.localState = this;

src/sqlancer/StatementExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void executeStatements() throws Exception {
7070
success = globalState.executeStatement(query);
7171
} while (nextAction.canBeRetried() && !success
7272
&& nrTries++ < globalState.getOptions().getNrStatementRetryCount());
73-
} catch (IgnoreMeException e) {
73+
} catch (IgnoreMeException ignored) {
7474

7575
}
7676
if (query != null && query.couldAffectSchema()) {

src/sqlancer/common/DBMSCommon.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static boolean matchesIndexName(String indexName) {
2727
return matcher.matches();
2828
}
2929

30-
public static int getMaxIndexInDoubleArrary(double... doubleArray) {
30+
public static int getMaxIndexInDoubleArray(double... doubleArray) {
3131
int maxIndex = 0;
3232
double maxValue = 0.0;
3333
for (int j = 0; j < doubleArray.length; j++) {

src/sqlancer/common/ast/BinaryNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public abstract class BinaryNode<T> implements BinaryOperation<T> {
77
private final T left;
88
private final T right;
99

10-
public BinaryNode(T left, T right) {
10+
protected BinaryNode(T left, T right) {
1111
this.left = left;
1212
this.right = right;
1313
}

src/sqlancer/common/ast/BinaryOperatorNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public interface Operator {
1010
String getTextRepresentation();
1111
}
1212

13-
public BinaryOperatorNode(T left, T right, O op) {
13+
protected BinaryOperatorNode(T left, T right, O op) {
1414
super(left, right);
1515
this.op = op;
1616
}

src/sqlancer/common/ast/FunctionNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public abstract class FunctionNode<F, A> {
77
protected F function;
88
protected List<A> args;
99

10-
public FunctionNode(F function, List<A> args) {
10+
protected FunctionNode(F function, List<A> args) {
1111
this.function = function;
1212
this.args = args;
1313
}

src/sqlancer/common/ast/TernaryNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public abstract class TernaryNode<T> implements BinaryOperation<T> {
88
private final T middle;
99
private final T right;
1010

11-
public TernaryNode(T left, T middle, T right) {
11+
protected TernaryNode(T left, T middle, T right) {
1212
this.left = left;
1313
this.middle = middle;
1414
this.right = right;

0 commit comments

Comments
 (0)