LUCENE-5463: Unbreak forbidden APIs for Solr, remove broken RUE.sizeOf(String) and add new forbidden APIs to the Maven build.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1571493 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Adrien Grand 2014-02-24 23:44:14 +00:00
parent b7290ceab4
commit f3af8c97be
11 changed files with 69 additions and 14 deletions

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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">

View File

@ -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.

View File

@ -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() {

View File

@ -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;

View File

@ -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 runtime
org.apache.lucene.util.RamUsageEstimator#sizeOf(java.lang.Object)
org.apache.lucene.util.RamUsageEstimator#humanSizeOf(java.lang.Object)

View File

@ -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"/>