Skip to content

Apache Lucene open-source search software

SOLR-13568: Precommit fail Java var until 9x. Fail var...

Erick Ericksonf6f1b4244c40
diff --git a/lucene/tools/src/groovy/check-source-patterns.groovy b/lucene/tools/src/groovy/check-source-patterns.groovy
index 779496331e3..62565e67d49 100644
--- a/lucene/tools/src/groovy/check-source-patterns.groovy
+++ b/lucene/tools/src/groovy/check-source-patterns.groovy
@@ -49,6 +49,13 @@ def invalidPatterns = [
(~$/import java\.lang\.\w+;/$) : 'java.lang import is unnecessary'
]
+// 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'
+]
+
+
def baseDir = properties['basedir'];
def baseDirLen = baseDir.length() + 1;
@@ -200,6 +207,11 @@ ant.fileScanner{
reportViolation(f, "Solr test cases should extend SolrTestCase rather than LuceneTestCase");
}
}
+ invalidJavaOnlyPatterns.each { pattern,name ->
+ if (pattern.matcher(text).find()) {
+ reportViolation(f, name);
+ }
+ }
}
if (f.name.endsWith('.xml') || f.name.endsWith('.xml.template')) {
checkLicenseHeaderPrecedes(f, '<tag>', xmlTagPattern, xmlCommentPattern, text, ratDocument);
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 833b489cf46..afa9eb12777 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -166,6 +166,8 @@ Other Changes
* SOLR-13573: Add SolrRangeQuery getters for upper, lower bound (Brian Rhees via Jason Gerlowski)
+* SOLR-13658: Precommit fail Java "var" until 9x. Fail "var...<>" constructs entirely (Erick Erickson)
+
================== 8.2.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
index 67a3651142b..ad707872c94 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
@@ -18,6 +18,7 @@ package org.apache.solr.client.solrj;
import java.io.ByteArrayInputStream;
+import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -688,15 +689,15 @@ abstract public class SolrExampleTests extends SolrExampleTestsBase
Assert.assertEquals(0, rsp.getResults().getNumFound());
ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update");
- var file = getFile("solrj/books.csv");
+ File file = getFile("solrj/books.csv");
final int opened[] = new int[] {0};
final int closed[] = new int[] {0};
- var assertClosed = random().nextBoolean();
+ boolean assertClosed = random().nextBoolean();
if (assertClosed) {
- var allBytes = Files.readAllBytes(file.toPath());
-
- var contentStreamMock = new ContentStreamBase.ByteArrayStream(allBytes, "solrj/books.csv", "application/csv") {
+ byte[] allBytes = Files.readAllBytes(file.toPath());
+
+ ContentStreamBase.ByteArrayStream contentStreamMock = new ContentStreamBase.ByteArrayStream(allBytes, "solrj/books.csv", "application/csv") {
@Override
public InputStream getStream() throws IOException {
opened [0]++;