Apache Solr open-source search software
LUCENE-6795: Forbid AccessibleObject#setAccessible and suppress legitimate uses / wrap with doPrivileged
Uwe Schindlerb8a213ccf7e7
diff --git a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterDeleteQueue.java b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterDeleteQueue.javaindex d1c05a2385b..9265cb3d09c 100644--- a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterDeleteQueue.java+++ b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterDeleteQueue.java@@ -77,8 +77,9 @@ final class DocumentsWriterDeleteQueue implements Accountable {private final DeleteSlice globalSlice;private final BufferedUpdates globalBufferedUpdates;- /* only acquired to update the global deletes */- private final ReentrantLock globalBufferLock = new ReentrantLock();++ // only acquired to update the global deletes, pkg-private for access by tests:+ final ReentrantLock globalBufferLock = new ReentrantLock();final long generation;diff --git a/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java b/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.javaindex 65486d41d77..0808eb65a1d 100644--- a/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java+++ b/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java@@ -35,6 +35,7 @@ import java.lang.reflect.Method;import org.apache.lucene.store.ByteBufferIndexInput.BufferCleaner;import org.apache.lucene.util.Constants;+import org.apache.lucene.util.SuppressForbidden;/** File-based {@link Directory} implementation that uses* mmap for reading, and {@link@@ -165,6 +166,7 @@ public class MMapDirectory extends FSDirectory {public static final boolean UNMAP_SUPPORTED =AccessController.doPrivileged((PrivilegedAction<Boolean>) MMapDirectory::checkUnmapSupported);+ @SuppressForbidden(reason = "Java 9 Jigsaw whitelists access to sun.misc.Cleaner, so setAccessible works")private static boolean checkUnmapSupported() {try {Class<?> clazz = Class.forName("java.nio.DirectByteBuffer");@@ -307,16 +309,20 @@ public class MMapDirectory extends FSDirectory {return newIoe;}- private static final BufferCleaner CLEANER = (ByteBufferIndexInput parent, ByteBuffer buffer) -> {+ private static final BufferCleaner CLEANER = (final ByteBufferIndexInput parent, final ByteBuffer buffer) -> {try {- AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {- final Method getCleanerMethod = buffer.getClass().getMethod("cleaner");- getCleanerMethod.setAccessible(true);- final Object cleaner = getCleanerMethod.invoke(buffer);- if (cleaner != null) {- cleaner.getClass().getMethod("clean").invoke(cleaner);+ AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {+ @Override+ @SuppressForbidden(reason = "Java 9 Jigsaw whitelists access to sun.misc.Cleaner, so setAccessible works")+ public Void run() throws Exception {+ final Method getCleanerMethod = buffer.getClass().getMethod("cleaner");+ getCleanerMethod.setAccessible(true);+ final Object cleaner = getCleanerMethod.invoke(buffer);+ if (cleaner != null) {+ cleaner.getClass().getMethod("clean").invoke(cleaner);+ }+ return null;}- return null;});} catch (PrivilegedActionException e) {throw new IOException("Unable to unmap the mapped buffer: " + parent.toString(), e.getCause());diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDocumentsWriterDeleteQueue.java b/lucene/core/src/test/org/apache/lucene/index/TestDocumentsWriterDeleteQueue.javaindex 64f1b8d1f22..cc0cfb3d592 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestDocumentsWriterDeleteQueue.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestDocumentsWriterDeleteQueue.java@@ -17,7 +17,6 @@ package org.apache.lucene.index;* the License.*/-import java.lang.reflect.Field;import java.util.HashSet;import java.util.Set;import java.util.concurrent.CountDownLatch;@@ -149,10 +148,7 @@ public class TestDocumentsWriterDeleteQueue extends LuceneTestCase {NoSuchFieldException, IllegalArgumentException, IllegalAccessException,InterruptedException {final DocumentsWriterDeleteQueue queue = new DocumentsWriterDeleteQueue();- Field field = DocumentsWriterDeleteQueue.class- .getDeclaredField("globalBufferLock");- field.setAccessible(true);- ReentrantLock lock = (ReentrantLock) field.get(queue);+ ReentrantLock lock = queue.globalBufferLock;lock.lock();Thread t = new Thread() {@Overridediff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOnJRECrash.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOnJRECrash.javaindex 5d1b92f98aa..777ef46d4a1 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOnJRECrash.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOnJRECrash.java@@ -41,6 +41,7 @@ import org.apache.lucene.util.SuppressForbidden;import org.apache.lucene.util.TestUtil;import com.carrotsearch.randomizedtesting.SeedUtils;+/*** Runs TestNRTThreads in a separate process, crashes the JRE in the middle* of execution, then runs checkindex to make sure it's not corrupt.@@ -187,6 +188,7 @@ public class TestIndexWriterOnJRECrash extends TestNRTThreads {/*** currently, this only works/tested on Sun and IBM.*/+ @SuppressForbidden(reason = "We need Unsafe to actually crush :-)")public void crashJRE() {final String vendor = Constants.JAVA_VENDOR;final boolean supportsUnsafeNpeDereference =diff --git a/lucene/sandbox/src/java/org/apache/lucene/sandbox/queries/regex/JakartaRegexpCapabilities.java b/lucene/sandbox/src/java/org/apache/lucene/sandbox/queries/regex/JakartaRegexpCapabilities.javaindex 5996f9cbfc0..1641e7fcc71 100644--- a/lucene/sandbox/src/java/org/apache/lucene/sandbox/queries/regex/JakartaRegexpCapabilities.java+++ b/lucene/sandbox/src/java/org/apache/lucene/sandbox/queries/regex/JakartaRegexpCapabilities.java@@ -18,9 +18,8 @@ package org.apache.lucene.sandbox.queries.regex;*/import org.apache.lucene.util.BytesRef;-import org.apache.lucene.util.CharsRef;import org.apache.lucene.util.CharsRefBuilder;-import org.apache.lucene.util.UnicodeUtil;+import org.apache.lucene.util.SuppressForbidden;import org.apache.regexp.CharacterIterator;import org.apache.regexp.RE;import org.apache.regexp.REProgram;@@ -40,6 +39,11 @@ public class JakartaRegexpCapabilities implements RegexCapabilities {private static Method getPrefixMethod;static {+ initClass();+ }++ @SuppressForbidden(reason = "TODO: Remove this class completely and also the hack around setAccessible!")+ private static void initClass() {try {getPrefixMethod = REProgram.class.getMethod("getPrefix");} catch (Exception e) {diff --git a/lucene/sandbox/src/java/org/apache/lucene/sandbox/queries/regex/JavaUtilRegexCapabilities.java b/lucene/sandbox/src/java/org/apache/lucene/sandbox/queries/regex/JavaUtilRegexCapabilities.javaindex 13d0324fe21..05b5a609624 100644--- a/lucene/sandbox/src/java/org/apache/lucene/sandbox/queries/regex/JavaUtilRegexCapabilities.java+++ b/lucene/sandbox/src/java/org/apache/lucene/sandbox/queries/regex/JavaUtilRegexCapabilities.java@@ -21,9 +21,7 @@ import java.util.regex.Matcher;import java.util.regex.Pattern;import org.apache.lucene.util.BytesRef;-import org.apache.lucene.util.CharsRef;import org.apache.lucene.util.CharsRefBuilder;-import org.apache.lucene.util.UnicodeUtil;/*** An implementation tying Java's built-in java.util.regex to RegexQuery.diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/IndexWriterMaxDocsChanger.java b/lucene/test-framework/src/java/org/apache/lucene/index/IndexWriterMaxDocsChanger.javanew file mode 100644index 00000000000..775a3def242--- /dev/null+++ b/lucene/test-framework/src/java/org/apache/lucene/index/IndexWriterMaxDocsChanger.java@@ -0,0 +1,47 @@+package org.apache.lucene.index;++import org.apache.lucene.util.LuceneTestCase;++/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++/**+ * Accessor to make some package protected methods in {@link IndexWriter} available for testing.+ * @lucene.internal+ */+public final class IndexWriterMaxDocsChanger {++ private IndexWriterMaxDocsChanger() {}++ /**+ * Tells {@link IndexWriter} to enforce the specified limit as the maximum number of documents in one index; call+ * {@link #restoreMaxDocs} once your test is done.+ * @see LuceneTestCase#setIndexWriterMaxDocs(int)+ */+ public static void setMaxDocs(int limit) {+ IndexWriter.setMaxDocs(limit);+ }++ /**+ * Returns to the default {@link IndexWriter#MAX_DOCS} limit.+ * @see LuceneTestCase#restoreIndexWriterMaxDocs()+ */+ public static void restoreMaxDocs() {+ IndexWriter.setMaxDocs(IndexWriter.MAX_DOCS);+ }++}diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.javaindex d4e8e6e4786..40ee8bf4f9f 100644--- a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java+++ b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java@@ -29,7 +29,6 @@ import java.lang.annotation.Retention;import java.lang.annotation.RetentionPolicy;import java.lang.annotation.Target;import java.lang.reflect.Constructor;-import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;import java.nio.file.NoSuchFileException;import java.nio.file.Path;@@ -684,23 +683,12 @@ public abstract class LuceneTestCase extends Assert {/** Tells {@link IndexWriter} to enforce the specified limit as the maximum number of documents in one index; call* {@link #restoreIndexWriterMaxDocs} once your test is done. */public void setIndexWriterMaxDocs(int limit) {- Method m;- try {- m = IndexWriter.class.getDeclaredMethod("setMaxDocs", int.class);- } catch (NoSuchMethodException nsme) {- throw new RuntimeException(nsme);- }- m.setAccessible(true);- try {- m.invoke(IndexWriter.class, limit);- } catch (IllegalAccessException | InvocationTargetException iae) {- throw new RuntimeException(iae);- }+ IndexWriterMaxDocsChanger.setMaxDocs(limit);}- /** Returns the default {@link IndexWriter#MAX_DOCS} limit. */+ /** Returns to the default {@link IndexWriter#MAX_DOCS} limit. */public void restoreIndexWriterMaxDocs() {- setIndexWriterMaxDocs(IndexWriter.MAX_DOCS);+ IndexWriterMaxDocsChanger.restoreMaxDocs();}// -----------------------------------------------------------------diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/RamUsageTester.java b/lucene/test-framework/src/java/org/apache/lucene/util/RamUsageTester.javaindex ebe3dc63f9e..561f258c0b8 100644--- a/lucene/test-framework/src/java/org/apache/lucene/util/RamUsageTester.java+++ b/lucene/test-framework/src/java/org/apache/lucene/util/RamUsageTester.java@@ -20,6 +20,8 @@ package org.apache.lucene.util;import java.lang.reflect.Array;import java.lang.reflect.Field;import java.lang.reflect.Modifier;+import java.security.AccessController;+import java.security.PrivilegedAction;import java.util.AbstractList;import java.util.ArrayList;import java.util.Collection;@@ -184,6 +186,7 @@ public final class RamUsageTester {* Create a cached information about shallow size and reference fields for* a given class.*/+ @SuppressForbidden(reason = "We need to access private fields of measured objects.")private static ClassCache createCacheEntry(final Class<?> clazz) {ClassCache cachedInfo;long shallowInstanceSize = RamUsageEstimator.NUM_BYTES_OBJECT_HEADER;@@ -199,8 +202,8 @@ public final class RamUsageTester {shallowInstanceSize = RamUsageEstimator.adjustForField(shallowInstanceSize, f);if (!f.getType().isPrimitive()) {- f.setAccessible(true);- referenceFields.add(f);+ final PrivilegedAction<Field> act = () -> { f.setAccessible(true); return f; };+ referenceFields.add(AccessController.doPrivileged(act));}}}diff --git a/lucene/tools/forbiddenApis/base.txt b/lucene/tools/forbiddenApis/base.txtindex ecfe3e4330e..39e2f78f304 100644--- a/lucene/tools/forbiddenApis/base.txt+++ b/lucene/tools/forbiddenApis/base.txt@@ -27,13 +27,16 @@ java.util.Properties#load(java.io.InputStream)java.util.Properties#save(java.io.OutputStream,java.lang.String)java.util.Properties#store(java.io.OutputStream,java.lang.String)+@defaultMessage Accessing private members of foreign classes breaks in security-sensitive environments. In addition, it no longer works with Java 9 on runtime classes.+java.lang.reflect.AccessibleObject#setAccessible(boolean)+java.lang.reflect.AccessibleObject#setAccessible(java.lang.reflect.AccessibleObject[],boolean)+java.lang.Character#codePointBefore(char[],int) @ Implicit start offset is error-prone when the char[] is a buffer and the first chars are random charsjava.lang.Character#codePointAt(char[],int) @ Implicit end offset is error-prone when the char[] is a buffer and the last chars are random charsjava.io.File#delete() @ use Files.delete for real exception, IOUtils.deleteFilesIgnoringExceptions if you dont care-@defaultMessage Use shuffle(List, Random) instead so that it can be reproduced-java.util.Collections#shuffle(java.util.List)+java.util.Collections#shuffle(java.util.List) @ Use shuffle(List, Random) instead so that it can be reproduced# START: forbidden-apis patch# TODO: remove this once forbidden-apis was updated to next version with following commit:diff --git a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/FieldStreamDataSource.java b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/FieldStreamDataSource.javaindex f8fcf92d62e..9a6232040fb 100644--- a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/FieldStreamDataSource.java+++ b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/FieldStreamDataSource.java@@ -16,17 +16,16 @@*/package org.apache.solr.handler.dataimport;-import org.slf4j.Logger;-import org.slf4j.LoggerFactory;+import static org.apache.solr.handler.dataimport.DataImportHandlerException.SEVERE;import java.io.ByteArrayInputStream;import java.io.InputStream;-import java.lang.reflect.Method;-import java.lang.reflect.Modifier;import java.sql.Blob;+import java.sql.SQLException;import java.util.Properties;-import static org.apache.solr.handler.dataimport.DataImportHandlerException.SEVERE;+import org.slf4j.Logger;+import org.slf4j.LoggerFactory;/**@@ -62,24 +61,13 @@ public class FieldStreamDataSource extends DataSource<InputStream> {Object o = wrapper.getVariableResolver().resolve(dataField);if (o == null) {throw new DataImportHandlerException(SEVERE, "No field available for name : " + dataField);- }- if (o instanceof Blob) {+ } else if (o instanceof Blob) {Blob blob = (Blob) o;try {- //Most of the JDBC drivers have getBinaryStream defined as public- // so let us just check it- Method m = blob.getClass().getDeclaredMethod("getBinaryStream");- if (Modifier.isPublic(m.getModifiers())) {- return (InputStream) m.invoke(blob);- } else {- // force invoke- m.setAccessible(true);- return (InputStream) m.invoke(blob);- }- } catch (Exception e) {+ return blob.getBinaryStream();+ } catch (SQLException sqle) {LOG.info("Unable to get data from BLOB");return null;-}} else if (o instanceof byte[]) {byte[] bytes = (byte[]) o;diff --git a/solr/core/src/test/org/apache/solr/cloud/SolrXmlInZkTest.java b/solr/core/src/test/org/apache/solr/cloud/SolrXmlInZkTest.javaindex e741e7fe312..ff672213bf2 100644--- a/solr/core/src/test/org/apache/solr/cloud/SolrXmlInZkTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/SolrXmlInZkTest.java@@ -17,8 +17,10 @@ package org.apache.solr.cloud;*/import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;+import org.apache.commons.io.FileUtils;import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.common.SolrException;import org.apache.solr.common.cloud.SolrZkClient;import org.apache.solr.common.cloud.ZkStateReader;import org.apache.solr.core.NodeConfig;@@ -30,8 +32,6 @@ import org.junit.rules.RuleChain;import org.junit.rules.TestRule;import java.io.File;-import java.lang.reflect.InvocationTargetException;-import java.lang.reflect.Method;import java.nio.charset.StandardCharsets;import java.util.Properties;@@ -50,15 +50,6 @@ public class SolrXmlInZkTest extends SolrTestCaseJ4 {private NodeConfig cfg;- private SolrDispatchFilter solrDispatchFilter;-- @After- public void after() {- if (solrDispatchFilter != null) {- solrDispatchFilter.destroy();- }- }-private void setUpZkAndDiskXml(boolean toZk, boolean leaveOnLocal) throws Exception {File tmpDir = createTempDir().toFile();File solrHome = new File(tmpDir, "home");@@ -95,13 +86,7 @@ public class SolrXmlInZkTest extends SolrTestCaseJ4 {props.setProperty("solr.test.sys.prop1", "propone");props.setProperty("solr.test.sys.prop2", "proptwo");- Method method = SolrDispatchFilter.class.getDeclaredMethod("loadNodeConfig", String.class, Properties.class);- method.setAccessible(true);- if (solrDispatchFilter != null) solrDispatchFilter.destroy();- solrDispatchFilter = new SolrDispatchFilter();- Object obj = method.invoke(solrDispatchFilter, solrHome.getAbsolutePath(), props);- cfg = (NodeConfig) obj;-+ cfg = SolrDispatchFilter.loadNodeConfig(solrHome.getAbsolutePath(), props);log.info("####SETUP_END " + getTestName());}@@ -155,9 +140,9 @@ public class SolrXmlInZkTest extends SolrTestCaseJ4 {System.setProperty("hostPort", "8787");setUpZkAndDiskXml(false, false); // solr.xml not on disk eitherfail("Should have thrown an exception here");- } catch (InvocationTargetException ite) {+ } catch (SolrException solre) {assertTrue("Should be failing to create default solr.xml in code",- ite.getCause().getMessage().contains("solr.xml does not exist"));+ solre.getMessage().contains("solr.xml does not exist"));} finally {closeZK();}diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/beans/DocumentObjectBinder.java b/solr/solrj/src/java/org/apache/solr/client/solrj/beans/DocumentObjectBinder.javaindex 62cf95db1de..9550a415776 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/beans/DocumentObjectBinder.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/beans/DocumentObjectBinder.java@@ -19,8 +19,11 @@ package org.apache.solr.client.solrj.beans;import org.apache.solr.common.SolrDocumentList;import org.apache.solr.common.SolrDocument;import org.apache.solr.common.SolrInputDocument;+import org.apache.solr.common.util.SuppressForbidden;import java.lang.reflect.*;+import java.security.AccessController;+import java.security.PrivilegedAction;import java.util.*;import java.util.regex.Pattern;import java.util.concurrent.ConcurrentHashMap;@@ -123,6 +126,7 @@ public class DocumentObjectBinder {return fields;}+ @SuppressForbidden(reason = "Needs access to possibly private @Field annotated fields/methods")private List<DocField> collectInfo(Class clazz) {List<DocField> fields = new ArrayList<>();Class superClazz = clazz;@@ -136,7 +140,7 @@ public class DocumentObjectBinder {boolean childFieldFound = false;for (AccessibleObject member : members) {if (member.isAnnotationPresent(Field.class)) {- member.setAccessible(true);+ AccessController.doPrivileged((PrivilegedAction<Void>) () -> { member.setAccessible(true); return null; });DocField df = new DocField(member);if (df.child != null) {if (childFieldFound)diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.java b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.javaindex 35ad8bf9b04..6c6d49e1909 100644--- a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.java+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.java@@ -22,9 +22,12 @@ import java.lang.reflect.Field;import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;import java.net.SocketAddress;+import java.security.AccessController;+import java.security.PrivilegedAction;import java.util.Set;import java.util.concurrent.CopyOnWriteArraySet;+import org.apache.solr.common.util.SuppressForbidden;import org.apache.zookeeper.ClientCnxn;import org.apache.zookeeper.Watcher;import org.apache.zookeeper.ZooKeeper;@@ -55,34 +58,40 @@ public class SolrZooKeeper extends ZooKeeper {@Overridepublic void run() {try {- final ClientCnxn cnxn = getConnection();- synchronized (cnxn) {- try {- final Field sendThreadFld = cnxn.getClass().getDeclaredField("sendThread");- sendThreadFld.setAccessible(true);- Object sendThread = sendThreadFld.get(cnxn);- if (sendThread != null) {- Method method = sendThread.getClass().getDeclaredMethod("testableCloseSocket");- method.setAccessible(true);- try {- method.invoke(sendThread);- } catch (InvocationTargetException e) {- // is fine- }+ AccessController.doPrivileged((PrivilegedAction<Void>) this::closeZookeeperChannel);+ } finally {+ spawnedThreads.remove(this);+ }+ }++ @SuppressForbidden(reason = "Hack for Zookeper needs access to private methods.")+ private Void closeZookeeperChannel() {+ final ClientCnxn cnxn = getConnection();+ synchronized (cnxn) {+ try {+ final Field sendThreadFld = cnxn.getClass().getDeclaredField("sendThread");+ sendThreadFld.setAccessible(true);+ Object sendThread = sendThreadFld.get(cnxn);+ if (sendThread != null) {+ Method method = sendThread.getClass().getDeclaredMethod("testableCloseSocket");+ method.setAccessible(true);+ try {+ method.invoke(sendThread);+ } catch (InvocationTargetException e) {+ // is fine}- } catch (Exception e) {- throw new RuntimeException("Closing Zookeeper send channel failed.", e);}+ } catch (Exception e) {+ throw new RuntimeException("Closing Zookeeper send channel failed.", e);}- } finally {- spawnedThreads.remove(this);}+ return null; // Void}};spawnedThreads.add(t);t.start();}-+@Overridepublic synchronized void close() throws InterruptedException {for (Thread t : spawnedThreads) {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.javaindex 4840cb31a6a..fb47b979298 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@@ -25,10 +25,9 @@ import junit.framework.Assert;import org.apache.lucene.util.TestUtil;import org.apache.solr.SolrTestCaseJ4.SuppressSSL;import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;+import org.apache.solr.client.solrj.embedded.SolrExampleStreamingTest.ErrorTrackingConcurrentUpdateSolrClient;import org.apache.solr.client.solrj.impl.BinaryResponseParser;-import org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient;import org.apache.solr.client.solrj.impl.HttpSolrClient;-import org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException;import org.apache.solr.client.solrj.impl.NoOpResponseParser;import org.apache.solr.client.solrj.impl.XMLResponseParser;import org.apache.solr.client.solrj.request.AbstractUpdateRequest;@@ -48,7 +47,6 @@ import org.apache.solr.client.solrj.response.RangeFacet.Count;import org.apache.solr.common.SolrDocument;import org.apache.solr.common.SolrDocumentList;import org.apache.solr.common.SolrException;-import org.apache.solr.common.SolrException.ErrorCode;import org.apache.solr.common.SolrInputDocument;import org.apache.solr.common.params.AnalysisParams;import org.apache.solr.common.params.CommonParams;@@ -61,7 +59,6 @@ import org.slf4j.Logger;import org.slf4j.LoggerFactory;import java.io.IOException;-import java.lang.reflect.Field;import java.util.ArrayList;import java.util.Arrays;import java.util.Collection;@@ -458,27 +455,18 @@ abstract public class SolrExampleTests extends SolrExampleTestsBase} catch (Throwable t) {Assert.fail("should have thrown a SolrException! not: " + t);}- } else if (client instanceof ConcurrentUpdateSolrClient) {+ } else if (client instanceof ErrorTrackingConcurrentUpdateSolrClient) {//XXX concurrentupdatesolrserver reports errors differently- ConcurrentUpdateSolrClient concurrentClient = (ConcurrentUpdateSolrClient) client;- Field field = getConcurrentClientExceptionField(concurrentClient);- field.set(concurrentClient, null);+ ErrorTrackingConcurrentUpdateSolrClient concurrentClient = (ErrorTrackingConcurrentUpdateSolrClient) client;+ concurrentClient.lastError = null;concurrentClient.add(doc);concurrentClient.blockUntilFinished();- Throwable lastError = (Throwable)field.get(concurrentClient);- assertNotNull("Should throw exception!", lastError); //XXX+ assertNotNull("Should throw exception!", concurrentClient.lastError);} else {log.info("Ignoring update test for client:" + client.getClass().getName());}}- private static Field getConcurrentClientExceptionField(Object cs)- throws SecurityException, NoSuchFieldException, IllegalArgumentException {- Field field = cs.getClass().getDeclaredField("lastError");- field.setAccessible(true);- return field;- }-@Testpublic void testAugmentFields() throws Exception{@@ -1639,7 +1627,9 @@ abstract public class SolrExampleTests extends SolrExampleTestsBasefail("Operation should throw an exception!");} else {client.commit(); //just to be sure the client has sent the doc- assertTrue("ConcurrentUpdateSolrClient did not report an error", ((Throwable) getConcurrentClientExceptionField(client).get(client)).getMessage().contains("Conflict"));+ ErrorTrackingConcurrentUpdateSolrClient concurrentClient = (ErrorTrackingConcurrentUpdateSolrClient) client;+ assertNotNull("ConcurrentUpdateSolrClient did not report an error", concurrentClient.lastError);+ assertTrue("ConcurrentUpdateSolrClient did not report an error", concurrentClient.lastError.getMessage().contains("Conflict"));}} catch (SolrException se) {assertTrue("No identifiable error message", se.getMessage().contains("version conflict for unique"));diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingTest.javaindex e953c35c025..76964808acb 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingTest.java@@ -46,6 +46,19 @@ public class SolrExampleStreamingTest extends SolrExampleTests {public static void beforeTest() throws Exception {createJetty(legacyExampleCollection1SolrHome());}++ public class ErrorTrackingConcurrentUpdateSolrClient extends ConcurrentUpdateSolrClient {+ public Throwable lastError = null;++ public ErrorTrackingConcurrentUpdateSolrClient(String solrServerUrl, int queueSize, int threadCount) {+ super(solrServerUrl, queueSize, threadCount);+ }++ @Override+ public void handleError(Throwable ex) {+ handledException = lastError = ex;+ }+ }@Overridepublic SolrClient createNewSolrClient()@@ -54,15 +67,7 @@ public class SolrExampleStreamingTest extends SolrExampleTests {// setup the server...String url = jetty.getBaseUrl().toString() + "/collection1";// smaller queue size hits locks more often- ConcurrentUpdateSolrClient concurrentClient = new ConcurrentUpdateSolrClient( url, 2, 5 ) {-- public Throwable lastError = null;- @Override- public void handleError(Throwable ex) {- handledException = lastError = ex;- }- };-+ ConcurrentUpdateSolrClient concurrentClient = new ErrorTrackingConcurrentUpdateSolrClient( url, 2, 5 );concurrentClient.setParser(new XMLResponseParser());concurrentClient.setRequestWriter(new RequestWriter());return concurrentClient;