Apache Solr open-source search software
LUCENE-5463: Unbreak forbidden APIs for Solr, remove broken RUE.sizeOf(String) and add new forbidden APIs to the Maven build.
Adrien Grandf3af8c97be5d
diff --git a/dev-tools/maven/lucene/core/src/java/pom.xml.template b/dev-tools/maven/lucene/core/src/java/pom.xml.templateindex 22f01c6f3e6..70100b4c8f9 100644--- a/dev-tools/maven/lucene/core/src/java/pom.xml.template+++ b/dev-tools/maven/lucene/core/src/java/pom.xml.template@@ -113,6 +113,22 @@<goal>check</goal></goals></execution>+ <execution>+ <id>check-rue</id> <!-- separate execution to specify excludes -->+ <configuration>+ <signaturesFiles>+ <signaturesFile>${top-level}/lucene/tools/forbiddenApis/rue.txt</signaturesFile>+ </signaturesFiles>+ <excludes>+ <exclude>org/apache/lucene/search/FieldCache$CacheEntry.class</exclude>+ <exclude>org/apache/lucene/util/RamUsageEstimator.class</exclude>+ <exclude>org/apache/lucene/search/CachingWrapperFilter.class</exclude>+ </excludes>+ </configuration>+ <goals>+ <goal>check</goal>+ </goals>+ </execution></executions></plugin></plugins>diff --git a/dev-tools/maven/lucene/memory/pom.xml.template b/dev-tools/maven/lucene/memory/pom.xml.templateindex 08b15cb03dd..f3729d183d9 100644--- a/dev-tools/maven/lucene/memory/pom.xml.template+++ b/dev-tools/maven/lucene/memory/pom.xml.template@@ -66,5 +66,49 @@</excludes></testResource></testResources>+ <plugins>+ <plugin>+ <groupId>de.thetaphi</groupId>+ <artifactId>forbiddenapis</artifactId>+ <executions>+ <execution>+ <id>lucene-shared-check-forbidden-apis</id>+ <phase>none</phase> <!-- Block inherited execution -->+ </execution>+ <execution>+ <id>check-forbidden-apis</id>+ <configuration>+ <!-- disallow undocumented classes like sun.misc.Unsafe: -->+ <internalRuntimeForbidden>true</internalRuntimeForbidden>+ <bundledSignatures>+ <bundledSignature>jdk-unsafe</bundledSignature>+ <bundledSignature>jdk-deprecated</bundledSignature>+ <bundledSignature>jdk-system-out</bundledSignature>+ </bundledSignatures>+ <signaturesFiles>+ <signaturesFile>${top-level}/lucene/tools/forbiddenApis/base.txt</signaturesFile>+ </signaturesFiles>+ </configuration>+ <goals>+ <goal>check</goal>+ </goals>+ </execution>+ <execution>+ <id>check-rue</id> <!-- separate execution to specify excludes -->+ <configuration>+ <signaturesFiles>+ <signaturesFile>${top-level}/lucene/tools/forbiddenApis/rue.txt</signaturesFile>+ </signaturesFiles>+ <excludes>+ <exclude>org/apache/lucene/index/memory/MemoryIndex.class</exclude>+ </excludes>+ </configuration>+ <goals>+ <goal>check</goal>+ </goals>+ </execution>+ </executions>+ </plugin>+ </plugins></build></project>diff --git a/dev-tools/maven/lucene/pom.xml.template b/dev-tools/maven/lucene/pom.xml.templateindex 6709d3b227d..2bf0112797c 100644--- a/dev-tools/maven/lucene/pom.xml.template+++ b/dev-tools/maven/lucene/pom.xml.template@@ -79,6 +79,7 @@</bundledSignatures><signaturesFiles><signaturesFile>${top-level}/lucene/tools/forbiddenApis/base.txt</signaturesFile>+ <signaturesFile>${top-level}/lucene/tools/forbiddenApis/rue.txt</signaturesFile></signaturesFiles></configuration><goals>diff --git a/dev-tools/maven/solr/core/src/java/pom.xml.template b/dev-tools/maven/solr/core/src/java/pom.xml.templateindex da05bf95ea4..2b012737c3d 100644--- a/dev-tools/maven/solr/core/src/java/pom.xml.template+++ b/dev-tools/maven/solr/core/src/java/pom.xml.template@@ -89,6 +89,7 @@<signaturesFiles><signaturesFile>${top-level}/lucene/tools/forbiddenApis/base.txt</signaturesFile><signaturesFile>${top-level}/lucene/tools/forbiddenApis/servlet-api.txt</signaturesFile>+ <signaturesFile>${top-level}/lucene/tools/forbiddenApis/rue.txt</signaturesFile></signaturesFiles></configuration><goals>diff --git a/dev-tools/maven/solr/pom.xml.template b/dev-tools/maven/solr/pom.xml.templateindex 73ceda700b5..2eca1c35417 100644--- a/dev-tools/maven/solr/pom.xml.template+++ b/dev-tools/maven/solr/pom.xml.template@@ -127,6 +127,7 @@</bundledSignatures><signaturesFiles><signaturesFile>${top-level}/lucene/tools/forbiddenApis/base.txt</signaturesFile>+ <signaturesFile>${top-level}/lucene/tools/forbiddenApis/rue.txt</signaturesFile></signaturesFiles></configuration><goals>diff --git a/lucene/common-build.xml b/lucene/common-build.xmlindex 45d030fb8bc..7728731fd32 100644--- a/lucene/common-build.xml+++ b/lucene/common-build.xml@@ -2212,7 +2212,7 @@ ${ant.project.name}.test.dependencies=${test.classpath.list}</path></target>- <target name="check-forbidden-apis" depends="-check-forbidden-all,-check-forbidden-tests,-check-forbidden-sources" description="Check forbidden API calls in compiled class files"/>+ <target name="check-forbidden-apis" depends="-check-forbidden-all,-check-forbidden-core,-check-forbidden-tests" description="Check forbidden API calls in compiled class files"/><!-- applies to both source and test code --><target name="-check-forbidden-all" depends="-init-forbidden-apis,compile-core,compile-test">@@ -2233,7 +2233,7 @@ ${ant.project.name}.test.dependencies=${test.classpath.list}</target><!-- applies to only source code -->- <target name="-check-forbidden-sources" depends="-init-forbidden-apis,compile-core,-check-forbidden-sysout,-check-forbidden-rue" />+ <target name="-check-forbidden-core" depends="-init-forbidden-apis,compile-core,-check-forbidden-sysout,-check-forbidden-rue" /><target name="-check-forbidden-rue" depends="-init-forbidden-apis,compile-core"><forbidden-apis signaturesFile="${common.dir}/tools/forbiddenApis/rue.txt" classpathref="forbidden-apis.allclasses.classpath">diff --git a/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java b/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.javaindex 88ab5f9cc48..06cad08ec68 100644--- a/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java+++ b/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java@@ -320,11 +320,6 @@ public final class RamUsageEstimator {return alignObjectSize((long) NUM_BYTES_ARRAY_HEADER + (long) NUM_BYTES_DOUBLE * arr.length);}- /** Returns the size in bytes of the String object. */- public static long sizeOf(String s) {- return shallowSizeOf(s) + alignObjectSize(NUM_BYTES_ARRAY_HEADER + NUM_BYTES_CHAR * s.length());- }-/*** Estimates the RAM usage by the given object. It will* walk the object tree and sum up all referenced objects.diff --git a/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java b/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.javaindex cb5442a4f93..9f46ba7d191 100644--- a/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java+++ b/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java@@ -86,10 +86,6 @@ public class TestRamUsageEstimator extends LuceneTestCase {double[] array = new double[rnd.nextInt(1024)];assertEquals(sizeOf(array), sizeOf((Object) array));}- {- String s = RandomStrings.randomUnicodeOfCodepointLength(random(), random().nextInt(10));- assertEquals(sizeOf(s), sizeOf((Object) s));- }}public void testReferenceSize() {diff --git a/lucene/suggest/src/java/org/apache/lucene/search/suggest/tst/TernaryTreeNode.java b/lucene/suggest/src/java/org/apache/lucene/search/suggest/tst/TernaryTreeNode.javaindex 9af35cac236..922db550406 100644--- a/lucene/suggest/src/java/org/apache/lucene/search/suggest/tst/TernaryTreeNode.java+++ b/lucene/suggest/src/java/org/apache/lucene/search/suggest/tst/TernaryTreeNode.java@@ -57,7 +57,7 @@ public class TernaryTreeNode {mem += hiKid.sizeInBytes();}if (token != null) {- mem += RamUsageEstimator.sizeOf(token);+ mem += RamUsageEstimator.shallowSizeOf(token) + RamUsageEstimator.NUM_BYTES_ARRAY_HEADER + RamUsageEstimator.NUM_BYTES_CHAR * token.length();}mem += RamUsageEstimator.shallowSizeOf(val);return mem;diff --git a/lucene/tools/forbiddenApis/rue.txt b/lucene/tools/forbiddenApis/rue.txtindex f558cb716e2..45b38404d19 100644--- a/lucene/tools/forbiddenApis/rue.txt+++ b/lucene/tools/forbiddenApis/rue.txt@@ -13,7 +13,7 @@# See the License for the specific language governing permissions and# limitations under the License.-@defaultMessage slow+@defaultMessage This method is useful for testing but is slow at runtimeorg.apache.lucene.util.RamUsageEstimator#sizeOf(java.lang.Object)org.apache.lucene.util.RamUsageEstimator#humanSizeOf(java.lang.Object)diff --git a/solr/common-build.xml b/solr/common-build.xmlindex 65f754ce10b..dc3e810177c 100644--- a/solr/common-build.xml+++ b/solr/common-build.xml@@ -468,7 +468,7 @@</target><!-- Forbidden API Task, customizations for Solr -->- <target name="-check-forbidden-base" depends="-init-forbidden-apis,compile-core,compile-test">+ <target name="-check-forbidden-core" depends="-init-forbidden-apis,compile-core,compile-test"><property file="${common.dir}/ivy-versions.properties"/> <!-- for commons-io version --><forbidden-apis internalRuntimeForbidden="true" classpathref="forbidden-apis.allclasses.classpath"><bundledSignatures name="jdk-unsafe-${javac.target}"/>@@ -477,6 +477,7 @@<signaturesFileSet dir="${common.dir}/tools/forbiddenApis"><include name="base.txt" /><include name="servlet-api.txt" />+ <include name="rue.txt" /></signaturesFileSet><fileset dir="${build.dir}/classes/java" excludes="${forbidden-base-excludes}"/><fileset dir="${build.dir}/classes/test" excludes="${forbidden-tests-excludes}" erroronmissingdir="false"/>