Skip to content

Commit a71c429

Browse files
authored
build: enable ClassInitializationDeadlock, SuppressWarnings the problems (#15322)
Enable error-prone's ClassInitializationDeadlock check, which can statically detect bugs such as #15317 All problems were just suppressed with a 'FIXME' message, this check will at least prevent any new ones from showing up. There aren't that many problems, it just happens that some are caused by generated code, so you get a violation for each bit-per-value.
1 parent 6a1ff24 commit a71c429

File tree

9 files changed

+17
-3
lines changed

9 files changed

+17
-3
lines changed

build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/ErrorPronePlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public void apply(Project project) {
323323
"CheckReturnValue:OFF", // we don't use these annotations
324324
"CheckedExceptionNotThrown:OFF", // TODO: new, not checked if applicable to Lucene
325325
"ClassCanBeStatic:OFF", // noisy
326-
"ClassInitializationDeadlock:OFF", // TODO: there are problems
326+
"ClassInitializationDeadlock:ERROR",
327327
"ClassName:OFF", // TODO: new, not checked if applicable to Lucene
328328
"ClassNamedLikeTypeParameter:OFF", // TODO: new, not checked if applicable to Lucene
329329
"ClassNewInstance:WARN",

gradle/regenerate/moman/gen_BulkOperation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ def p64_decode(bpv, f, bits):
285285
*/\n''')
286286

287287
f.write('abstract class BulkOperation implements PackedInts.Decoder, PackedInts.Encoder {\n')
288+
f.write(' @SuppressWarnings("ClassInitializationDeadlock") // FIXME: may cause hangs!\n')
288289
f.write(' private static final BulkOperation[] packedBulkOps = new BulkOperation[] {\n')
289290

290291
for bpv in range(1, 65):
@@ -310,6 +311,7 @@ def p64_decode(bpv, f, bits):
310311
f.write('\n')
311312

312313
f.write(' // NOTE: this is sparse (some entries are null):\n')
314+
f.write(' @SuppressWarnings("ClassInitializationDeadlock") // FIXME: may cause hangs!\n')
313315
f.write(' private static final BulkOperation[] packedSingleBlockBulkOps = new BulkOperation[] {\n')
314316
for bpv in range(1, max(PACKED_64_SINGLE_BLOCK_BPV) + 1):
315317
if bpv in PACKED_64_SINGLE_BLOCK_BPV:

lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/TrecDocParser.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* Parser for trec doc content, invoked on doc text excluding <DOC> and <DOCNO> which
2929
* are handled in TrecContentSource. Required to be stateless and hence thread safe.
3030
*/
31+
@SuppressWarnings("ClassInitializationDeadlock") // FIXME: may cause hangs!
3132
public abstract class TrecDocParser {
3233

3334
/** Types of trec parse paths, */

lucene/core/src/generated/checksums/utilGenPacked.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"gradle/regenerate/moman/gen_BulkOperation.py": "d721930b5dae7f938b52a17700eb84b157930b2b",
2+
"gradle/regenerate/moman/gen_BulkOperation.py": "da9eccf0c8dd33325df5f1e76a1de74226035734",
33
"gradle/regenerate/moman/gen_Packed64SingleBlock.py": "0fd2a498c3edbd195a68c2d1d686be0aed51a104",
4-
"lucene/core/src/java/org/apache/lucene/util/packed/BulkOperation.java": "c4e16930960a18e74802c56ee60f8e83bd8b6dd2",
4+
"lucene/core/src/java/org/apache/lucene/util/packed/BulkOperation.java": "35a89e4f3dd37084cc059a784bcbeb384256773b",
55
"lucene/core/src/java/org/apache/lucene/util/packed/BulkOperationPacked.java": "2b0d9226bae8a07ce4970bcaa9d4d0cd4fe2c79a",
66
"lucene/core/src/java/org/apache/lucene/util/packed/BulkOperationPacked1.java": "c483aa35c275bacc1f3a010c5b879441be502108",
77
"lucene/core/src/java/org/apache/lucene/util/packed/BulkOperationPacked10.java": "35fe8a9c9a91cd840b239af4ddd1e0de53ef1404",

lucene/core/src/java/org/apache/lucene/analysis/CharArrayMap.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
*/
3333
public class CharArrayMap<V> extends AbstractMap<Object, V> {
3434
// private only because missing generics
35+
@SuppressWarnings("ClassInitializationDeadlock") // FIXME: may cause hangs!
3536
private static final CharArrayMap<?> EMPTY_MAP = new EmptyCharArrayMap<>();
3637

3738
private static final int INIT_SIZE = 8;

lucene/core/src/java/org/apache/lucene/index/TermsEnum.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ public final PostingsEnum postings(PostingsEnum reuse) throws IOException {
196196
* Attributes to it. This should not be a problem, as the enum is always empty and the existence
197197
* of unused Attributes does not matter.
198198
*/
199+
@SuppressWarnings("ClassInitializationDeadlock") // FIXME: may cause hangs!
199200
public static final TermsEnum EMPTY =
200201
new BaseTermsEnum() {
201202

lucene/core/src/java/org/apache/lucene/store/IOContext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ interface FileOpenHint {}
5050
* <p>It will use {@link ReadAdvice#RANDOM} by default, unless set by system property {@code
5151
* org.apache.lucene.store.defaultReadAdvice}.
5252
*/
53+
@SuppressWarnings("ClassInitializationDeadlock") // FIXME: may cause hangs!
5354
IOContext DEFAULT = new DefaultIOContext();
5455

5556
/**
@@ -58,6 +59,7 @@ interface FileOpenHint {}
5859
* <p>This context should only be used when the read operations will be performed in the same
5960
* thread as the thread that opens the underlying storage.
6061
*/
62+
@SuppressWarnings("ClassInitializationDeadlock") // FIXME: may cause hangs!
6163
IOContext READONCE = new DefaultIOContext(DataAccessHint.SEQUENTIAL, ReadOnceHint.INSTANCE);
6264

6365
/** Returns an {@link IOContext} for merging with the specified {@link MergeInfo} */

lucene/core/src/java/org/apache/lucene/util/packed/BulkOperation.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
/** Efficient sequential read/write of packed integers. */
2222
abstract class BulkOperation implements PackedInts.Decoder, PackedInts.Encoder {
23+
@SuppressWarnings("ClassInitializationDeadlock") // FIXME: may cause hangs!
2324
private static final BulkOperation[] packedBulkOps =
2425
new BulkOperation[] {
2526
new BulkOperationPacked1(),
@@ -89,6 +90,7 @@ abstract class BulkOperation implements PackedInts.Decoder, PackedInts.Encoder {
8990
};
9091

9192
// NOTE: this is sparse (some entries are null):
93+
@SuppressWarnings("ClassInitializationDeadlock") // FIXME: may cause hangs!
9294
private static final BulkOperation[] packedSingleBlockBulkOps =
9395
new BulkOperation[] {
9496
new BulkOperationPackedSingleBlock(1),

lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/DistanceStyle.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,23 @@ public interface DistanceStyle {
2626
// convenient access to built-in styles:
2727

2828
/** Arc distance calculator */
29+
@SuppressWarnings("ClassInitializationDeadlock") // FIXME: may cause hangs!
2930
public static final ArcDistance ARC = ArcDistance.INSTANCE;
3031

3132
/** Linear distance calculator */
33+
@SuppressWarnings("ClassInitializationDeadlock") // FIXME: may cause hangs!
3234
public static final LinearDistance LINEAR = LinearDistance.INSTANCE;
3335

3436
/** Linear distance squared calculator */
37+
@SuppressWarnings("ClassInitializationDeadlock") // FIXME: may cause hangs!
3538
public static final LinearSquaredDistance LINEAR_SQUARED = LinearSquaredDistance.INSTANCE;
3639

3740
/** Normal distance calculator */
41+
@SuppressWarnings("ClassInitializationDeadlock") // FIXME: may cause hangs!
3842
public static final NormalDistance NORMAL = NormalDistance.INSTANCE;
3943

4044
/** Normal distance squared calculator */
45+
@SuppressWarnings("ClassInitializationDeadlock") // FIXME: may cause hangs!
4146
public static final NormalSquaredDistance NORMAL_SQUARED = NormalSquaredDistance.INSTANCE;
4247

4348
/**

0 commit comments

Comments
 (0)