Skip to content

Commit 4266bc4

Browse files
committed
Assign private constructors to utility classes and add a Checkstyle rule
1 parent 73d39e5 commit 4266bc4

File tree

72 files changed

+240
-38
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+240
-38
lines changed

checkstyle.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<!-- Checks for Size Violations. -->
7272
<!-- See https://checkstyle.org/config_sizes.html -->
7373
<module name="FileLength"/>
74-
<!-- <module name="LineLength">
74+
<!-- we do not care about the line length: <module name="LineLength">
7575
<property name="fileExtensions" value="java"/>
7676
</module> -->
7777

@@ -175,7 +175,7 @@
175175
<!-- See https://checkstyle.org/config_design.html -->
176176
<!-- TODO: enable <module name="DesignForExtension"/> -->
177177
<!-- TODO: <module name="FinalClass"/> -->
178-
<!-- TODO: <module name="HideUtilityClassConstructor"/> -->
178+
<module name="HideUtilityClassConstructor"/>
179179
<module name="InterfaceIsType"/>
180180
<!-- TODO: <module name="VisibilityModifier"/> -->
181181

src/sqlancer/LikeImplementationHelper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
public class LikeImplementationHelper {
44

5+
private LikeImplementationHelper() {
6+
}
7+
58
public static boolean match(String str, String regex, int regexPosition, int strPosition, boolean caseSensitive) {
69
if (strPosition == str.length() && regexPosition == regex.length()) {
710
return true;

src/sqlancer/Main.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public class Main {
5151
}
5252
}
5353

54+
private Main() {
55+
}
56+
5457
public static final class StateLogger {
5558

5659
private final File loggerFile;

src/sqlancer/clickhouse/ClickhouseErrors.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
public class ClickhouseErrors {
66

7+
private ClickhouseErrors() {
8+
}
9+
710
public static void addExpressionErrors(Set<String> errors) {
811
// errors.add("Illegal type (String) of argument of function not");
912
// errors.add("Illegal type String of column for constant filter. Must be UInt8 or Nullable(UInt8)");

src/sqlancer/clickhouse/ast/ClickhouseConstant.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
public class ClickhouseConstant implements Node<ClickhouseExpression> {
66

7+
private ClickhouseConstant() {
8+
}
9+
710
public static class ClickhouseNullConstant extends ClickhouseConstant {
811

912
@Override
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package sqlancer.cockroachdb;
2+
3+
public class CockroachDBBugs {
4+
5+
private CockroachDBBugs() {
6+
}
7+
8+
// https://github.com/cockroachdb/cockroach/issues/46915
9+
public static boolean bug46915 = true;
10+
11+
// https://github.com/cockroachdb/cockroach/issues/45703
12+
public static boolean bug45703 = true;
13+
14+
// https://github.com/cockroachdb/cockroach/issues/44757
15+
public static boolean bug44757 = true;
16+
}

src/sqlancer/cockroachdb/CockroachDBCommon.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
public class CockroachDBCommon {
1313

14+
private CockroachDBCommon() {
15+
}
16+
1417
public static String getRandomCollate() {
1518
return Randomly.fromOptions("en", "de", "es", "cmn");
1619
}

src/sqlancer/cockroachdb/CockroachDBErrors.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44

55
public class CockroachDBErrors {
66

7+
private CockroachDBErrors() {
8+
}
9+
710
public static void addExpressionErrors(Set<String> errors) {
811
errors.add(" non-streaming operator encountered when vectorize=auto");
912

10-
if (true) {
11-
// https://github.com/cockroachdb/cockroach/issues/46915
13+
if (CockroachDBBugs.bug46915) {
1214
errors.add("ERROR: at or near \"unknown\": syntax error");
1315
}
1416

15-
if (true) {
16-
// https://github.com/cockroachdb/cockroach/issues/45703
17+
if (CockroachDBBugs.bug45703) {
1718
errors.add("github.com/cockroachdb/cockroach/pkg/sql/execinfra/expr.go:78: processExpression()");
1819
}
1920

@@ -155,16 +156,11 @@ public static void addExpressionErrors(Set<String> errors) {
155156
errors.add("could not parse JSON: unable to decode JSON: unexpected EOF");
156157
errors.add("can't order by column type jsonb");
157158

158-
if (true) {
159-
errors.add("aggregate functions are not allowed in GROUP BY");
160-
errors.add(" must appear in the GROUP BY clause or be used in an aggregate function"); // TODO: better
161-
// control what is
162-
// generated in a
163-
// view
164-
}
159+
// TODO: better control what is generated in a view
160+
errors.add("aggregate functions are not allowed in GROUP BY");
161+
errors.add(" must appear in the GROUP BY clause or be used in an aggregate function");
165162

166-
if (true) {
167-
// TODO https://github.com/cockroachdb/cockroach/issues/44757
163+
if (CockroachDBBugs.bug44757) {
168164
errors.add("no builtin aggregate");
169165
}
170166

src/sqlancer/cockroachdb/CockroachDBProvider.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import sqlancer.TestOracle;
2828
import sqlancer.cockroachdb.CockroachDBProvider.CockroachDBGlobalState;
2929
import sqlancer.cockroachdb.CockroachDBSchema.CockroachDBTable;
30+
import sqlancer.cockroachdb.gen.CockroachDBCommentOnGenerator;
3031
import sqlancer.cockroachdb.gen.CockroachDBCreateStatisticsGenerator;
3132
import sqlancer.cockroachdb.gen.CockroachDBDeleteGenerator;
3233
import sqlancer.cockroachdb.gen.CockroachDBIndexGenerator;
@@ -39,7 +40,6 @@
3940
import sqlancer.cockroachdb.gen.CockroachDBTruncateGenerator;
4041
import sqlancer.cockroachdb.gen.CockroachDBUpdateGenerator;
4142
import sqlancer.cockroachdb.gen.CockroachDBViewGenerator;
42-
import sqlancer.cockroachdb.gen.RockroachDBCommentOnGenerator;
4343

4444
public class CockroachDBProvider implements DatabaseProvider<CockroachDBGlobalState, CockroachDBOptions> {
4545

@@ -52,14 +52,13 @@ public enum Action {
5252
UPDATE(CockroachDBUpdateGenerator::gen), //
5353
CREATE_VIEW(CockroachDBViewGenerator::generate), //
5454
SET_CLUSTER_SETTING(CockroachDBSetClusterSettingGenerator::create), DELETE(
55-
CockroachDBDeleteGenerator::delete), COMMENT_ON(RockroachDBCommentOnGenerator::comment), SHOW(
55+
CockroachDBDeleteGenerator::delete), COMMENT_ON(CockroachDBCommentOnGenerator::comment), SHOW(
5656
CockroachDBShowGenerator::show), TRANSACTION((g) -> {
5757
String s = Randomly.fromOptions("BEGIN", "ROLLBACK", "COMMIT");
5858
return new QueryAdapter(s, Arrays.asList("there is no transaction in progress",
5959
"there is already a transaction in progress", "current transaction is aborted",
6060
"does not exist" /* interleaved indexes */));
6161
}), EXPLAIN((g) -> {
62-
new CockroachDBRandomQuerySynthesizer();
6362
StringBuilder sb = new StringBuilder("EXPLAIN ");
6463
Set<String> errors = new HashSet<>();
6564
if (Randomly.getBoolean()) {
@@ -177,7 +176,7 @@ public void generateAndTestDatabase(CockroachDBGlobalState globalState) throws S
177176
}
178177
logger.currentFileWriter = null;
179178
} catch (IgnoreMeException e) {
180-
179+
// continue trying
181180
}
182181
} while (!success);
183182
globalState.setSchema(CockroachDBSchema.fromConnection(con, databaseName));

src/sqlancer/cockroachdb/CockroachDBSchema.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public static CockroachDBSchema fromConnection(Connection con, String databaseNa
293293
List<String> tableNames = getTableNames(con);
294294
for (String tableName : tableNames) {
295295
List<CockroachDBColumn> databaseColumns = getTableColumns(con, tableName);
296-
List<TableIndex> indexes = getIndexes(con, tableName, databaseName);
296+
List<TableIndex> indexes = getIndexes(con, tableName);
297297
boolean isView = tableName.startsWith("v");
298298
CockroachDBTable t = new CockroachDBTable(tableName, databaseColumns, indexes, isView);
299299
for (CockroachDBColumn c : databaseColumns) {
@@ -318,8 +318,7 @@ private static List<String> getTableNames(Connection con) throws SQLException {
318318
return tableNames;
319319
}
320320

321-
private static List<TableIndex> getIndexes(Connection con, String tableName, String databaseName)
322-
throws SQLException {
321+
private static List<TableIndex> getIndexes(Connection con, String tableName) throws SQLException {
323322
List<TableIndex> indexes = new ArrayList<>();
324323
try (Statement s = con.createStatement()) {
325324
try (ResultSet rs = s.executeQuery(String.format("SHOW INDEX FROM %s", tableName))) {

0 commit comments

Comments
 (0)