Browse Source

raise a more useful error when a class cannot be loaded because of a SecurityException in the hasmethod condition. PR 51035.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1095270 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 14 years ago
parent
commit
171a1f35e3
3 changed files with 76 additions and 4 deletions
  1. +7
    -0
      WHATSNEW
  2. +6
    -4
      src/main/org/apache/tools/ant/taskdefs/condition/HasMethod.java
  3. +63
    -0
      src/tests/antunit/taskdefs/condition/hasmethod-text.xml

+ 7
- 0
WHATSNEW View File

@@ -37,6 +37,13 @@ Fixed bugs:
* Resource collection implementation of mapped PropertySet returned
unusable resources.

* The hasmethod condition failed with a NullPointerException when
ignoresystemclasses is true and Ant tried to load a "restricted
class" - i.e. a class that the Java VM will only accept when loaded
via the bootclassloader (a java.* class).
It will now fail with a more useful error message.
Bugzilla Report 51035.

Other changes:
--------------



+ 6
- 4
src/main/org/apache/tools/ant/taskdefs/condition/HasMethod.java View File

@@ -113,10 +113,12 @@ public class HasMethod extends ProjectComponent implements Condition {
try {
return loader.findClass(classname);
} catch (SecurityException se) {
// class found but restricted name; this is
// actually the case we're looking for in JDK 1.3+,
// so catch the exception and return
return null;
// class found but restricted name
throw new BuildException("class \"" + classname
+ "\" was found but a"
+ " SecurityException has been"
+ " raised while loading it",
se);
}
} else if (loader != null) {
// How do we ever get here?


+ 63
- 0
src/tests/antunit/taskdefs/condition/hasmethod-text.xml View File

@@ -0,0 +1,63 @@
<?xml version="1.0"?>
<!--
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.
-->
<project name="equals-test" xmlns:au="antlib:org.apache.ant.antunit"
default="antunit">

<import file="../../antunit-base.xml" />

<target name="test-missingclass">
<au:expectfailure
expectedMessage='class "org.example.somepackage.Foo" was not found'>
<condition property="foo">
<hasmethod classname="org.example.somepackage.Foo"
method="bar"/>
</condition>
</au:expectfailure>
</target>

<target name="test-missingclass-no-sysclasspath">
<au:expectfailure
expectedMessage='class "org.example.somepackage.Foo" was not found'>
<condition property="foo">
<hasmethod classname="org.example.somepackage.Foo"
ignoreSystemClasses="true"
method="bar"/>
</condition>
</au:expectfailure>
</target>

<target name="test-restricted-class">
<au:assertFalse>
<hasmethod classname="java.lang.String"
method="bar"/>
</au:assertFalse>
</target>

<target name="test-restricted-class-no-sysclasspath">
<au:expectfailure
expectedMessage='class "java.lang.String" was found but a SecurityException has been raised while loading it'>
<condition property="foo">
<hasmethod classname="java.lang.String"
classpath="${java.home}/lib/rt.jar"
ignoreSystemClasses="true"
method="bar"/>
</condition>
</au:expectfailure>
</target>

</project>

Loading…
Cancel
Save