Skip to content

Apache Lucene open-source search software

LUCENE-10136: allow 'var' declarations in source code (be reasonable though). (#368)

Dawid Weissa613021ca482
diff --git a/gradle/validation/validate-source-patterns.gradle b/gradle/validation/validate-source-patterns.gradle
index d59b5e56412..0eea752d18d 100644
--- a/gradle/validation/validate-source-patterns.gradle
+++ b/gradle/validation/validate-source-patterns.gradle
@@ -115,7 +115,6 @@ configure(rootProject) {
// default excludes.
exclude '**/build/**'
- exclude 'dev-tools/missing-doclet/src/**/*.java' // <-- TODO: remove once we allow "var" on master
// ourselves :-)
exclude 'gradle/validation/validate-source-patterns.gradle'
@@ -157,8 +156,7 @@ class ValidateSourcePatternsTask extends DefaultTask {
// Python and others merrily use var declarations, this is a problem _only_ in Java at least for 8x where we're forbidding var declarations
def invalidJavaOnlyPatterns = [
- (~$/\n\s*var\s+.*=.*<>.*/$) : 'Diamond operators should not be used with var',
- (~$/\n\s*var\s+/$) : 'var is not allowed in until we stop development on the 8x code line'
+ (~$/\n\s*var\s+.*=.*<>.*/$) : 'Diamond operators should not be used with var'
]
def found = 0;
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 046f2ad07f3..3c4ab42fe22 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -359,6 +359,8 @@ Changes in Backwards Compatibility Policy
Other
+* LUCENE-10136: allow 'var' declarations in source code (Dawid Weiss)
+
* LUCENE-9570, LUCENE-9564: Apply google java format and enforce it on source Java files.
Review diffs and correct automatic formatting oddities. (Erick Erickson,
Bruno Roustant, Dawid Weiss)
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
index cc8d50fccc3..d80b1022c0f 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
@@ -1965,7 +1965,7 @@ public class TestIndexWriter extends LuceneTestCase {
Map<String, String> data = new HashMap<>();
Iterable<Map.Entry<String, String>> iter = writer.getLiveCommitData();
if (iter != null) {
- for (Map.Entry<String, String> ent : iter) {
+ for (var ent : iter) {
data.put(ent.getKey(), ent.getValue());
}
}