Skip to content

Commit f1194b0

Browse files
authored
Enable strict compiler settings (#413)
This change enforces javac compiler warnings and linting as errors as a part of #406.
1 parent b4b3668 commit f1194b0

File tree

144 files changed

+389
-219
lines changed

Some content is hidden

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

144 files changed

+389
-219
lines changed

.devcontainer/devcontainer.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@
4040
"settings": {},
4141
// Add the IDs of extensions you want installed when the container is created.
4242
"extensions": [
43-
"github.vscode-github-actions",
43+
"EditorConfig.EditorConfig",
4444
"GitHub.copilot",
4545
"eamodio.gitlens",
46-
"vscjava.vscode-java-pack",
47-
"EditorConfig.EditorConfig"
46+
"github.vscode-github-actions",
47+
"github.vscode-pull-request-github",
48+
"huntertran.auto-markdown-toc",
49+
"vscjava.vscode-java-pack"
4850
]
4951
}
5052
},

.vscode/extensions.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"recommendations": [
3+
"EditorConfig.EditorConfig",
4+
"github.vscode-pull-request-github",
5+
"huntertran.auto-markdown-toc",
6+
"vscjava.vscode-java-pack"
7+
]
8+
}

CONTRIBUTING.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Contributing
2+
3+
We welcome all contributions! Please open a [pull request](https://github.com/cmu-db/benchbase/pulls). Common contributions may include:
4+
5+
- Adding support for a new DBMS.
6+
- Adding more tests of existing benchmarks.
7+
- Fixing any bugs or known issues.
8+
9+
## Contents
10+
11+
<!-- TOC -->
12+
13+
- [Contributing](#contributing)
14+
- [Contents](#contents)
15+
- [IDE](#ide)
16+
- [Adding a new DBMS](#adding-a-new-dbms)
17+
- [Java Development Notes](#java-development-notes)
18+
- [Avoid var keyword](#avoid-var-keyword)
19+
- [Compiler Warnings](#compiler-warnings)
20+
- [Alternatives to arrays of generics](#alternatives-to-arrays-of-generics)
21+
22+
<!-- /TOC -->
23+
24+
## IDE
25+
26+
Although you can use any IDE you prefer, there are some configurations for [VSCode](https://code.visualstudio.com/) that you may find useful included in the repository, including [Github Codespaces](https://github.com/features/codespaces) and [VSCode devcontainer](https://code.visualstudio.com/docs/remote/containers) support to automatically handle dependencies, environment setup, code formatting, and more.
27+
28+
## Adding a new DBMS
29+
30+
Please see the existing MySQL and PostgreSQL code for an example.
31+
32+
## Java Development Notes
33+
34+
### Compiler Warnings
35+
36+
In an effort to enforce clean, safe, maintainable code, [PR #413](https://github.com/cmu-db/benchbase/pull/413) enabled the `-Werror` and `-Xlint:all` options for the `javac` compiler.
37+
38+
This means that any compiler warnings will cause the build to fail.
39+
40+
If you are seeing a build failure due to a compiler warning, please fix the warning or (on rare occassions) add an exception to the line causing the issue.
41+
42+
### Avoid `var` keyword
43+
44+
In general, we prefer to avoid the `var` keyword in favor of explicit types.
45+
46+
#### Alternatives to arrays of generics
47+
48+
Per the [Java Language Specification](https://docs.oracle.com/javase/tutorial/java/generics/restrictions.html#createArrays), arrays of generic types are not allowed and will cause compiler warnings (e.g., `unchecked cast`)
49+
50+
In some cases, you can extend a generic type to create a non-generic type that can be used in an array.
51+
52+
For instance,
53+
54+
```java
55+
// Simple generic class overload to avoid some cast warnings.
56+
class SomeTypeList extends LinkedList<SomeType> {}
57+
58+
SomeTypeList[] someTypeLists = new SomeTypeList[] {
59+
new SomeTypeList(),
60+
new SomeTypeList(),
61+
new SomeTypeList(),
62+
};
63+
```
64+
65+
#### `this-escape` warnings
66+
67+
`possible 'this' escape before subclass is fully initialized`
68+
69+
The `this-escape` warning above is caused by passing using `this.someOverridableMethod()` in a constructor.
70+
This could in theory cause problems with a subclass not being fully initialized when the method is called.
71+
72+
Since many of our classes are not designed to be subclassed, we can safely ignore this warning by marking the class as `final` rather than completely rewrite the class initialization.

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,17 @@ Please see the existing MySQL and PostgreSQL code for an example.
221221

222222
## Contributing
223223

224-
We welcome all contributions! Please open a pull request. Common contributions may include:
224+
We welcome all contributions! Please open a [pull request](https://github.com/cmu-db/benchbase/pulls). Common contributions may include:
225225

226226
- Adding support for a new DBMS.
227227
- Adding more tests of existing benchmarks.
228228
- Fixing any bugs or known issues.
229229

230+
Please see the [CONTRIBUTING.md](./CONTRIBUTING.md) for addition notes.
231+
230232
## Known Issues
231233

232-
Please use GitHub's issue tracker for all issues.
234+
Please use [GitHub's issue tracker](https://github.com/cmu-db/benchbase/issues) for all issues.
233235

234236
## Credits
235237

pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,20 @@
336336
<configuration>
337337
<source>${maven.compiler.source}</source>
338338
<target>${maven.compiler.target}</target>
339+
<showDeprecation>true</showDeprecation>
340+
<showWarnings>true</showWarnings>
341+
<compilerArgs>
342+
<!-- Enable all linter messages for the compiler. -->
343+
<!-- TODO: Remove annotations preprocess warning exception. -->
344+
<arg>-Xlint:all,-processing</arg>
345+
<!-- ignore annotation processing on generated class files -->
346+
<arg>-implicit:class</arg>
347+
<!-- TODO: Enable documentation linting.
348+
<arg>-Xdoclint:all</arg>
349+
-->
350+
<!-- Turn all warnings into errors to help keep the code clean. -->
351+
<arg>-Werror</arg>
352+
</compilerArgs>
339353
</configuration>
340354
</plugin>
341355
<plugin>

src/main/java/com/oltpbenchmark/DistributionStatistics.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.concurrent.TimeUnit;
2828

2929
public class DistributionStatistics {
30+
@SuppressWarnings("unused")
3031
private static final Logger LOG = LoggerFactory.getLogger(DistributionStatistics.class);
3132

3233
private static final double[] PERCENTILES = {0.0, 0.25, 0.5, 0.75, 0.9, 0.95, 0.99, 1.0};

src/main/java/com/oltpbenchmark/WorkloadState.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class WorkloadState {
4242
private final Iterator<Phase> phaseIterator;
4343

4444
private int workersWaiting = 0;
45+
@SuppressWarnings("unused") // never read
4546
private int workersWorking = 0;
4647
private int workerNeedSleep;
4748

@@ -60,7 +61,7 @@ public WorkloadState(BenchmarkState benchmarkState, List<Phase> works, int num_t
6061
*/
6162
public void addToQueue(int amount, boolean resetQueues) {
6263
int workAdded = 0;
63-
64+
6465
synchronized (this) {
6566
if (resetQueues) {
6667
workQueue.clear();
@@ -71,7 +72,7 @@ public void addToQueue(int amount, boolean resetQueues) {
7172
|| !currentPhase.isRateLimited() || currentPhase.isSerial()) {
7273
return;
7374
}
74-
75+
7576
// Add the specified number of procedures to the end of the queue.
7677
// If we can't keep up with current rate, truncate transactions
7778
for (int i = 0; i < amount && workQueue.size() <= RATE_QUEUE_LIMIT; ++i) {

src/main/java/com/oltpbenchmark/api/BenchmarkModule.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,15 @@ public abstract class BenchmarkModule {
7777
public BenchmarkModule(WorkloadConfiguration workConf) {
7878
this.workConf = workConf;
7979
this.dialects = new StatementDialects(workConf);
80-
initClassLoader();
80+
// setClassLoader();
81+
this.classLoader = ClassLoader.getSystemClassLoader();
8182
}
8283

8384
/**
8485
* Instantiates the classLoader variable, needs to be overwritten if
8586
* benchmark uses a custom implementation.
8687
*/
87-
protected void initClassLoader() {
88+
protected void setClassLoader() {
8889
this.classLoader = ClassLoader.getSystemClassLoader();
8990
}
9091

src/main/java/com/oltpbenchmark/api/StatementDialects.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.oltpbenchmark.WorkloadConfiguration;
2121
import com.oltpbenchmark.api.dialects.*;
2222
import com.oltpbenchmark.types.DatabaseType;
23-
import com.oltpbenchmark.types.State;
2423
import org.slf4j.Logger;
2524
import org.slf4j.LoggerFactory;
2625
import org.xml.sax.SAXException;
@@ -30,7 +29,6 @@
3029
import javax.xml.transform.stream.StreamSource;
3130
import javax.xml.validation.Schema;
3231
import javax.xml.validation.SchemaFactory;
33-
import java.io.File;
3432
import java.io.IOException;
3533
import java.io.InputStream;
3634
import java.io.StringWriter;
@@ -40,7 +38,7 @@
4038
/**
4139
* @author pavlo
4240
*/
43-
public class StatementDialects {
41+
public final class StatementDialects {
4442
private static final Logger LOG = LoggerFactory.getLogger(StatementDialects.class);
4543

4644
private static final DatabaseType DEFAULT_DB_TYPE = DatabaseType.MYSQL;

src/main/java/com/oltpbenchmark/benchmarks/auctionmark/AuctionMarkBenchmark.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@
3333
import java.util.ArrayList;
3434
import java.util.List;
3535

36-
public class AuctionMarkBenchmark extends BenchmarkModule {
37-
36+
public final class AuctionMarkBenchmark extends BenchmarkModule {
37+
@SuppressWarnings("unused")
3838
private static final Logger LOG = LoggerFactory.getLogger(AuctionMarkBenchmark.class);
3939

40-
4140
private final RandomGenerator rng = new RandomGenerator((int) System.currentTimeMillis());
4241

4342
public AuctionMarkBenchmark(WorkloadConfiguration workConf) {
@@ -70,6 +69,4 @@ protected List<Worker<? extends BenchmarkModule>> makeWorkersImpl() {
7069
protected Loader<AuctionMarkBenchmark> makeLoaderImpl() {
7170
return new AuctionMarkLoader(this);
7271
}
73-
74-
7572
}

src/main/java/com/oltpbenchmark/benchmarks/auctionmark/AuctionMarkLoader.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
* @author pavlo
4747
* @author visawee
4848
*/
49-
public class AuctionMarkLoader extends Loader<AuctionMarkBenchmark> {
49+
public final class AuctionMarkLoader extends Loader<AuctionMarkBenchmark> {
5050

5151
// -----------------------------------------------------------------
5252
// INTERNAL DATA MEMBERS
@@ -1195,6 +1195,7 @@ protected class ItemBidGenerator extends SubTableGenerator<LoaderItemInfo> {
11951195
private LoaderItemInfo.Bid bid = null;
11961196
private float currentBidPriceAdvanceStep;
11971197
private long currentCreateDateAdvanceStep;
1198+
@SuppressWarnings("unused") // only ever assigned
11981199
private float currentPrice;
11991200
private boolean new_item;
12001201

src/main/java/com/oltpbenchmark/benchmarks/auctionmark/AuctionMarkProfile.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public class AuctionMarkProfile {
7676
// ----------------------------------------------------------------
7777
// SERIALIZABLE DATA MEMBERS
7878
// ----------------------------------------------------------------
79+
static final long serialVersionUID = 0;
7980

8081
/**
8182
* Database Scale Factor
@@ -108,6 +109,14 @@ public class AuctionMarkProfile {
108109
*/
109110
protected transient Histogram<Integer> items_per_category = new Histogram<>();
110111

112+
/**
113+
* Simple generic class overload to avoid some cast warnings below.
114+
*/
115+
class ItemInfoList extends LinkedList<ItemInfo> {
116+
// Required serialization field.
117+
static final long serialVersionUID = 0;
118+
}
119+
111120
/**
112121
* Three status types for an item:
113122
* (1) Available - The auction of this item is still open
@@ -117,13 +126,13 @@ public class AuctionMarkProfile {
117126
* (3) Complete (The auction is closed and (There is no bid winner or
118127
* the bid winner has already purchased the item)
119128
*/
120-
private transient final LinkedList<ItemInfo> items_available = new LinkedList<>();
121-
private transient final LinkedList<ItemInfo> items_endingSoon = new LinkedList<>();
122-
private transient final LinkedList<ItemInfo> items_waitingForPurchase = new LinkedList<>();
123-
private transient final LinkedList<ItemInfo> items_completed = new LinkedList<>();
129+
private transient final ItemInfoList items_available = new ItemInfoList();
130+
private transient final ItemInfoList items_endingSoon = new ItemInfoList();
131+
private transient final ItemInfoList items_waitingForPurchase = new ItemInfoList();
132+
private transient final ItemInfoList items_completed = new ItemInfoList();
133+
124134

125-
@SuppressWarnings("unchecked")
126-
protected transient final LinkedList<ItemInfo>[] allItemSets = new LinkedList[]{
135+
protected transient final ItemInfoList allItemSets[] = new ItemInfoList[]{
127136
this.items_available,
128137
this.items_endingSoon,
129138
this.items_waitingForPurchase,
@@ -286,7 +295,7 @@ private AuctionMarkProfile copyProfile(AuctionMarkWorker worker, AuctionMarkProf
286295
this.items_per_category = other.items_per_category;
287296
this.gag_ids = other.gag_ids;
288297

289-
// Initialize the UserIdGenerator so we can figure out whether our
298+
// Initialize the UserIdGenerator so we can figure out whether our
290299
// client should even have these ids
291300
this.initializeUserIdGenerator(this.client_id);
292301

@@ -455,7 +464,6 @@ private static void loadItems(AuctionMarkProfile profile, List<Object[]> vt) {
455464

456465
private static void loadPendingItemComments(AuctionMarkProfile profile, List<Object[]> vt) {
457466
for (Object[] row : vt) {
458-
int col = 1;
459467
long ic_id = SQLUtil.getLong(row[0]);
460468
String ic_i_id = SQLUtil.getString(row[1]);
461469
String ic_u_id = SQLUtil.getString(row[2]);
@@ -712,6 +720,7 @@ private boolean addItem(LinkedList<ItemInfo> items, ItemInfo itemInfo) {
712720
// HACK: Always swap existing ItemInfos with our new one, since it will
713721
// more up-to-date information
714722
ItemInfo existing = items.set(idx, itemInfo);
723+
assert existing != null;
715724

716725
return (true);
717726
}
@@ -861,7 +870,7 @@ private ItemInfo getRandomItem(LinkedList<ItemInfo> itemSet, boolean needCurrent
861870
continue;
862871
}
863872

864-
// If they want an item that is ending in the future, then we compare it with
873+
// If they want an item that is ending in the future, then we compare it with
865874
// the current timestamp
866875
if (needFutureEndDate) {
867876
boolean compareTo = (temp.getEndDate().compareTo(currentTime) < 0);

0 commit comments

Comments
 (0)