Skip to content

Commit 46fb72a

Browse files
committed
ORC-2053: Use Java Set.of instead of Collections.emptySet
### What changes were proposed in this pull request? This PR aims to use Java 9+ `Set.of()` API instead of `Collections.emptySet()` and add a new checkstyle rule to ban `Collections.emptySet`. ### Why are the changes needed? We had better use `Set` simply and uniformly. ```java - import java.util.Collections; ... - private Set<Integer> filterColumnIds = Collections.emptySet(); + private Set<Integer> filterColumnIds = Set.of(); ``` ### Does this PR introduce _any_ user-facing change? No behavior change. ### How was this patch tested? Pass the CIs. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #2476 from dongjoon-hyun/ORC-2053. Authored-by: Dongjoon Hyun <dongjoon@apache.org> Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
1 parent 15fbd95 commit 46fb72a

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

java/checkstyle.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
<property name="ignoreComments" value="true"/>
5353
<property name="message" value="No starting LAND and LOR allowed."/>
5454
</module>
55+
<module name="RegexpSinglelineJava">
56+
<property name="format" value="Collections\.emptySet"/>
57+
<property name="message" value="Use Set.of() instead." />
58+
</module>
5559
<module name="Indentation">
5660
<property name="severity" value="error"/>
5761
<property name="basicOffset" value="2"/>

java/core/src/java/org/apache/orc/impl/TreeReaderFactory.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import java.text.DateFormat;
5454
import java.text.ParseException;
5555
import java.text.SimpleDateFormat;
56-
import java.util.Collections;
5756
import java.util.HashMap;
5857
import java.util.List;
5958
import java.util.Map;
@@ -143,7 +142,7 @@ public static class ReaderContext implements Context {
143142
private ReaderEncryption encryption;
144143
private boolean useProlepticGregorian;
145144
private boolean fileUsedProlepticGregorian;
146-
private Set<Integer> filterColumnIds = Collections.emptySet();
145+
private Set<Integer> filterColumnIds = Set.of();
147146
Consumer<OrcFilterContext> filterCallback;
148147

149148
public ReaderContext setSchemaEvolution(SchemaEvolution evolution) {

java/core/src/java/org/apache/orc/impl/reader/StripePlanner.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import java.security.Key;
4545
import java.util.ArrayList;
4646
import java.util.Arrays;
47-
import java.util.Collections;
4847
import java.util.HashMap;
4948
import java.util.List;
5049
import java.util.Map;
@@ -123,7 +122,7 @@ public StripePlanner(TypeDescription schema,
123122
boolean ignoreNonUtf8BloomFilter,
124123
long maxBufferSize) {
125124
this(schema, encryption, dataReader, version, ignoreNonUtf8BloomFilter, maxBufferSize,
126-
Collections.emptySet());
125+
Set.of());
127126
}
128127

129128
public StripePlanner(StripePlanner old) {

0 commit comments

Comments
 (0)