From 171a1f35e390455d105aaf43370c0475711a74c3 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 20 Apr 2011 05:10:21 +0000 Subject: [PATCH] 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 --- WHATSNEW | 7 +++ .../ant/taskdefs/condition/HasMethod.java | 10 +-- .../taskdefs/condition/hasmethod-text.xml | 63 +++++++++++++++++++ 3 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 src/tests/antunit/taskdefs/condition/hasmethod-text.xml diff --git a/WHATSNEW b/WHATSNEW index bd6725b5d..317f0285b 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -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: -------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/HasMethod.java b/src/main/org/apache/tools/ant/taskdefs/condition/HasMethod.java index 4f5ce5224..889a9f876 100644 --- a/src/main/org/apache/tools/ant/taskdefs/condition/HasMethod.java +++ b/src/main/org/apache/tools/ant/taskdefs/condition/HasMethod.java @@ -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? diff --git a/src/tests/antunit/taskdefs/condition/hasmethod-text.xml b/src/tests/antunit/taskdefs/condition/hasmethod-text.xml new file mode 100644 index 000000000..9ae9b323b --- /dev/null +++ b/src/tests/antunit/taskdefs/condition/hasmethod-text.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +