Skip to content

Commit d18af9a

Browse files
committed
Add checkstyle and fix the first batch of violations
1 parent da6cabe commit d18af9a

File tree

295 files changed

+1858
-1710
lines changed

Some content is hidden

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

295 files changed

+1858
-1710
lines changed

checkstyle.xml

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE module PUBLIC
3+
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
4+
"https://checkstyle.org/dtds/configuration_1_3.dtd">
5+
6+
<!--
7+
8+
Checkstyle configuration that checks the sun coding conventions from:
9+
10+
- the Java Language Specification at
11+
https://docs.oracle.com/javase/specs/jls/se11/html/index.html
12+
13+
- the Sun Code Conventions at https://www.oracle.com/technetwork/java/codeconvtoc-136057.html
14+
15+
- the Javadoc guidelines at
16+
https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html
17+
18+
- the JDK Api documentation https://docs.oracle.com/en/java/javase/11/
19+
20+
- some best practices
21+
22+
Checkstyle is very configurable. Be sure to read the documentation at
23+
https://checkstyle.org (or in your downloaded distribution).
24+
25+
Most Checks are configurable, be sure to consult the documentation.
26+
27+
To completely disable a check, just comment it out or delete it from the file.
28+
To suppress certain violations please review suppression filters.
29+
30+
Finally, it is worth reading the documentation.
31+
32+
-->
33+
34+
<module name="Checker">
35+
<!--
36+
If you set the basedir property below, then all reported file
37+
names will be relative to the specified directory. See
38+
https://checkstyle.org/config.html#Checker
39+
40+
<property name="basedir" value="${basedir}"/>
41+
-->
42+
<property name="severity" value="error"/>
43+
44+
<property name="fileExtensions" value="java, properties, xml"/>
45+
46+
<!-- Excludes all 'module-info.java' files -->
47+
<!-- See https://checkstyle.org/config_filefilters.html -->
48+
<module name="BeforeExecutionExclusionFileFilter">
49+
<property name="fileNamePattern" value="module\-info\.java$"/>
50+
</module>
51+
52+
<!-- https://checkstyle.org/config_filters.html#SuppressionFilter -->
53+
<module name="SuppressionFilter">
54+
<property name="file" value="${org.checkstyle.sun.suppressionfilter.config}"
55+
default="checkstyle-suppressions.xml" />
56+
<property name="optional" value="true"/>
57+
</module>
58+
59+
<!-- Checks that a package-info.java file exists for each package. -->
60+
<!-- See https://checkstyle.org/config_javadoc.html#JavadocPackage -->
61+
<!-- TODO: <module name="JavadocPackage"/> -->
62+
63+
<!-- Checks whether files end with a new line. -->
64+
<!-- See https://checkstyle.org/config_misc.html#NewlineAtEndOfFile -->
65+
<!-- TODO: <module name="NewlineAtEndOfFile"/> -->
66+
67+
<!-- Checks that property files contain the same keys. -->
68+
<!-- See https://checkstyle.org/config_misc.html#Translation -->
69+
<module name="Translation"/>
70+
71+
<!-- Checks for Size Violations. -->
72+
<!-- See https://checkstyle.org/config_sizes.html -->
73+
<module name="FileLength"/>
74+
<!-- <module name="LineLength">
75+
<property name="fileExtensions" value="java"/>
76+
</module> -->
77+
78+
<!-- Checks for whitespace -->
79+
<!-- See https://checkstyle.org/config_whitespace.html -->
80+
<!-- TODO: no tabs <module name="FileTabCharacter"/> -->
81+
82+
<!-- Miscellaneous other checks. -->
83+
<!-- See https://checkstyle.org/config_misc.html -->
84+
<module name="RegexpSingleline">
85+
<property name="format" value="\s+$"/>
86+
<property name="minimum" value="0"/>
87+
<property name="maximum" value="0"/>
88+
<property name="message" value="Line has trailing spaces."/>
89+
</module>
90+
91+
<!-- Checks for Headers -->
92+
<!-- See https://checkstyle.org/config_header.html -->
93+
<!-- <module name="Header"> -->
94+
<!-- <property name="headerFile" value="${checkstyle.header.file}"/> -->
95+
<!-- <property name="fileExtensions" value="java"/> -->
96+
<!-- </module> -->
97+
98+
<module name="TreeWalker">
99+
100+
<!-- Checks for Javadoc comments. -->
101+
<!-- See https://checkstyle.org/config_javadoc.html -->
102+
<module name="InvalidJavadocPosition"/>
103+
<!-- <module name="JavadocMethod"/> -->
104+
<!-- <module name="JavadocType"/>
105+
<module name="JavadocVariable"/>
106+
<module name="JavadocStyle"/>
107+
<module name="MissingJavadocMethod"/> -->
108+
109+
<!-- Checks for Naming Conventions. -->
110+
<!-- See https://checkstyle.org/config_naming.html -->
111+
<module name="ConstantName"/>
112+
<module name="LocalFinalVariableName"/>
113+
<module name="LocalVariableName"/>
114+
<module name="MemberName"/>
115+
<module name="MethodName"/>
116+
<module name="PackageName"/>
117+
<module name="ParameterName"/>
118+
<!-- TODO <module name="StaticVariableName"/> -->
119+
<module name="TypeName"/>
120+
121+
<!-- Checks for imports -->
122+
<!-- See https://checkstyle.org/config_imports.html -->
123+
<module name="AvoidStarImport"/>
124+
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
125+
<module name="RedundantImport"/>
126+
<module name="UnusedImports">
127+
<property name="processJavadoc" value="false"/>
128+
</module>
129+
130+
<!-- Checks for Size Violations. -->
131+
<!-- See https://checkstyle.org/config_sizes.html -->
132+
<!-- <module name="MethodLength"/> -->
133+
<!-- TODO: <module name="ParameterNumber"/> -->
134+
135+
<!-- Checks for whitespace -->
136+
<!-- See https://checkstyle.org/config_whitespace.html -->
137+
<module name="EmptyForIteratorPad"/>
138+
<module name="GenericWhitespace"/>
139+
<module name="MethodParamPad"/>
140+
<!-- <module name="NoWhitespaceAfter"/> -->
141+
<module name="NoWhitespaceBefore"/>
142+
<module name="OperatorWrap"/>
143+
<module name="ParenPad"/>
144+
<module name="TypecastParenPad"/>
145+
<module name="WhitespaceAfter"/>
146+
<module name="WhitespaceAround"/>
147+
148+
<!-- Modifier Checks -->
149+
<!-- See https://checkstyle.org/config_modifiers.html -->
150+
<!-- FIXME: <module name="ModifierOrder"/> -->
151+
<!-- FIXME: <module name="RedundantModifier"/> -->
152+
153+
<!-- Checks for blocks. You know, those {}'s -->
154+
<!-- See https://checkstyle.org/config_blocks.html -->
155+
<module name="AvoidNestedBlocks"/>
156+
<!-- TODO: <module name="EmptyBlock"/> -->
157+
<module name="LeftCurly"/>
158+
<module name="NeedBraces"/>
159+
<module name="RightCurly"/>
160+
161+
<!-- Checks for common coding problems -->
162+
<!-- See https://checkstyle.org/config_coding.html -->
163+
<module name="EmptyStatement"/>
164+
<module name="EqualsHashCode"/>
165+
<!-- TODO: <module name="HiddenField"/> -->
166+
<module name="IllegalInstantiation"/>
167+
<module name="InnerAssignment"/>
168+
<!-- TODO: enable and add exceptions: <module name="MagicNumber"/> -->
169+
<!-- TODO: <module name="MissingSwitchDefault"/> -->
170+
<module name="MultipleVariableDeclarations"/>
171+
<!-- TODO: <module name="SimplifyBooleanExpression"/> -->
172+
<module name="SimplifyBooleanReturn"/>
173+
174+
<!-- Checks for class design -->
175+
<!-- See https://checkstyle.org/config_design.html -->
176+
<!-- TODO: enable <module name="DesignForExtension"/> -->
177+
<!-- TODO: <module name="FinalClass"/> -->
178+
<!-- TODO: <module name="HideUtilityClassConstructor"/> -->
179+
<module name="InterfaceIsType"/>
180+
<!-- TODO: <module name="VisibilityModifier"/> -->
181+
182+
<!-- Miscellaneous other checks. -->
183+
<!-- See https://checkstyle.org/config_misc.html -->
184+
<module name="ArrayTypeStyle"/>
185+
<!-- <module name="FinalParameters"/> -->
186+
<!-- <module name="TodoComment"/> -->
187+
<module name="UpperEll"/>
188+
189+
<!-- https://checkstyle.org/config_filters.html#SuppressionXpathFilter -->
190+
<module name="SuppressionXpathFilter">
191+
<property name="file" value="${org.checkstyle.sun.suppressionxpathfilter.config}"
192+
default="checkstyle-xpath-suppressions.xml" />
193+
<property name="optional" value="true"/>
194+
</module>
195+
196+
</module>
197+
198+
</module>

pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,26 @@
5353
</archive>
5454
</configuration>
5555
</plugin>
56+
<plugin>
57+
<groupId>org.apache.maven.plugins</groupId>
58+
<artifactId>maven-checkstyle-plugin</artifactId>
59+
<version>3.1.1</version>
60+
<configuration>
61+
<configLocation>checkstyle.xml</configLocation>
62+
</configuration>
63+
<executions>
64+
<execution>
65+
<id>checkstyle</id>
66+
<phase>verify</phase>
67+
<goals>
68+
<goal>check</goal>
69+
</goals>
70+
<configuration>
71+
<failOnViolation>true</failOnViolation>
72+
</configuration>
73+
</execution>
74+
</executions>
75+
</plugin>
5676
</plugins>
5777
</build>
5878
<dependencies>

src/sqlancer/CompositeTestOracle.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
import java.util.List;
55

66
public class CompositeTestOracle implements TestOracle {
7-
7+
88
private final TestOracle[] oracles;
99
private int i;
10-
10+
1111
public CompositeTestOracle(List<TestOracle> oracles) {
1212
this.oracles = oracles.toArray(new TestOracle[oracles.size()]);
1313
}
14-
14+
1515
@Override
1616
public void check() throws SQLException {
1717
try {

src/sqlancer/DatabaseProvider.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,27 @@
1010
import java.util.Set;
1111

1212
public interface DatabaseProvider<G extends GlobalState<O>, O> {
13-
13+
1414
void generateAndTestDatabase(G globalState) throws SQLException;
1515

1616
G generateGlobalState();
1717

1818
// TODO: should be type G
1919
Connection createDatabase(GlobalState<?> globalState) throws SQLException;
2020

21-
2221
/**
23-
* The DBMS name is used to name the log directory and command to test the respective DBMS.
24-
*
25-
* @return
22+
* The DBMS name is used to name the log directory and command to test the
23+
* respective DBMS.
2624
*/
2725
String getDBMSName();
2826

29-
3027
// TODO: remove this
3128
default void printDatabaseSpecificState(FileWriter writer, StateToReproduce state) {
32-
29+
3330
}
3431

3532
StateToReproduce getStateToReproduce(String databaseName);
36-
33+
3734
O getCommand();
3835

3936
public static boolean isEqualDouble(String first, String second) {
@@ -47,14 +44,15 @@ public static boolean isEqualDouble(String first, String second) {
4744
}
4845

4946
public static boolean equals(double a, double b) {
50-
if (a == b)
47+
if (a == b) {
5148
return true;
49+
}
5250
// If the difference is less than epsilon, treat as equal.
5351
return Math.abs(a - b) < 0.0001 * Math.max(Math.abs(a), Math.abs(b));
5452
}
5553

56-
57-
public static List<String> getResultSetFirstColumnAsString(String queryString, Set<String> errors, Connection con, GlobalState<?> state) throws SQLException {
54+
public static List<String> getResultSetFirstColumnAsString(String queryString, Set<String> errors, Connection con,
55+
GlobalState<?> state) throws SQLException {
5856
if (state.getOptions().logEachSelect()) {
5957
// TODO: refactor me
6058
state.getLogger().writeCurrent(queryString);
@@ -102,5 +100,5 @@ public static List<String> getResultSetFirstColumnAsString(String queryString, S
102100
}
103101
return resultSet;
104102
}
105-
103+
106104
}

src/sqlancer/GlobalState.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ public class GlobalState<O> {
1515
private StateToReproduce state;
1616
private QueryManager manager;
1717
private String databaseName;
18-
18+
1919
public void setConnection(Connection con) {
2020
this.con = con;
2121
}
22-
22+
2323
@SuppressWarnings("unchecked")
2424
public void setDmbsSpecificOptions(Object dmbsSpecificOptions) {
2525
this.dmbsSpecificOptions = (O) dmbsSpecificOptions;
2626
}
27-
27+
2828
public O getDmbsSpecificOptions() {
2929
return dmbsSpecificOptions;
3030
}
@@ -72,11 +72,11 @@ public QueryManager getManager() {
7272
public void setManager(QueryManager manager) {
7373
this.manager = manager;
7474
}
75-
75+
7676
public String getDatabaseName() {
7777
return databaseName;
7878
}
79-
79+
8080
public void setDatabaseName(String databaseName) {
8181
this.databaseName = databaseName;
8282
}

src/sqlancer/Main.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public final static class StateLogger {
5757
private File curFile;
5858
private FileWriter logFileWriter;
5959
public FileWriter currentFileWriter;
60-
private static final List<String> initializedProvidersNames = new ArrayList<>();
60+
private static final List<String> INITIALIZED_PROVIDER_NAMES = new ArrayList<>();
6161
private boolean logEachSelect = true;
6262
private DatabaseProvider<?, ?> provider;
6363

@@ -95,7 +95,7 @@ public StateLogger(String databaseName, DatabaseProvider<?, ?> provider, MainOpt
9595
}
9696

9797
private synchronized void ensureExistsAndIsEmpty(File dir, DatabaseProvider<?, ?> provider) {
98-
if (initializedProvidersNames.contains(provider.getDBMSName())) {
98+
if (INITIALIZED_PROVIDER_NAMES.contains(provider.getDBMSName())) {
9999
return;
100100
}
101101
if (!dir.exists()) {
@@ -110,7 +110,7 @@ private synchronized void ensureExistsAndIsEmpty(File dir, DatabaseProvider<?, ?
110110
file.delete();
111111
}
112112
}
113-
initializedProvidersNames.add(provider.getDBMSName());
113+
INITIALIZED_PROVIDER_NAMES.add(provider.getDBMSName());
114114
}
115115

116116
private FileWriter getLogFileWriter() {
@@ -326,7 +326,7 @@ private void runThread(final String databaseName) {
326326
} catch (Exception e) {
327327
throw new AssertionError(e);
328328
}
329-
GlobalState<?> state = (GlobalState<?>) provider.generateGlobalState();
329+
GlobalState<?> state = provider.generateGlobalState();
330330
stateToRepro = provider.getStateToReproduce(databaseName);
331331
state.setState(stateToRepro);
332332
logger = new StateLogger(databaseName, provider, options);

0 commit comments

Comments
 (0)