Author: bodewig Date: Wed Apr 20 05:10:21 2011 New Revision: 1095270 URL: http://svn.apache.org/viewvc?rev=1095270&view=rev Log: raise a more useful error when a class cannot be loaded because of a SecurityException in the hasmethod condition. PR 51035.
Added: ant/core/trunk/src/tests/antunit/taskdefs/condition/hasmethod-text.xml (with props) Modified: ant/core/trunk/WHATSNEW ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/HasMethod.java Modified: ant/core/trunk/WHATSNEW URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=1095270&r1=1095269&r2=1095270&view=diff ============================================================================== --- ant/core/trunk/WHATSNEW (original) +++ ant/core/trunk/WHATSNEW Wed Apr 20 05:10:21 2011 @@ -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: -------------- Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/HasMethod.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/HasMethod.java?rev=1095270&r1=1095269&r2=1095270&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/HasMethod.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/HasMethod.java Wed Apr 20 05:10:21 2011 @@ -113,10 +113,12 @@ public class HasMethod extends ProjectCo 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? Added: ant/core/trunk/src/tests/antunit/taskdefs/condition/hasmethod-text.xml URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/condition/hasmethod-text.xml?rev=1095270&view=auto ============================================================================== --- ant/core/trunk/src/tests/antunit/taskdefs/condition/hasmethod-text.xml (added) +++ ant/core/trunk/src/tests/antunit/taskdefs/condition/hasmethod-text.xml Wed Apr 20 05:10:21 2011 @@ -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> Propchange: ant/core/trunk/src/tests/antunit/taskdefs/condition/hasmethod-text.xml ------------------------------------------------------------------------------ svn:eol-style = native