From be90dbd7b54f177a4ecf3b4de6d77366f34cad2e Mon Sep 17 00:00:00 2001 From: Steve Loughran Date: Sat, 1 Nov 2008 19:41:03 +0000 Subject: [PATCH] Bug ID 43660: JavaResource returns a null input stream if the resource is missing git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@709760 13f79535-47bb-0310-9956-ffa450edef68 --- .../ant/types/resources/JavaResource.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/org/apache/tools/ant/types/resources/JavaResource.java b/src/main/org/apache/tools/ant/types/resources/JavaResource.java index 13fd88be8..1d265c38b 100644 --- a/src/main/org/apache/tools/ant/types/resources/JavaResource.java +++ b/src/main/org/apache/tools/ant/types/resources/JavaResource.java @@ -17,6 +17,7 @@ */ package org.apache.tools.ant.types.resources; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; @@ -53,8 +54,21 @@ public class JavaResource extends AbstractClasspathResource { * @throws IOException if an error occurs. */ protected InputStream openInputStream(ClassLoader cl) throws IOException { - return cl == null ? ClassLoader.getSystemResourceAsStream(getName()) - : cl.getResourceAsStream(getName()); + InputStream inputStream; + if (cl == null) { + inputStream = ClassLoader.getSystemResourceAsStream(getName()); + if (inputStream == null) { + throw new FileNotFoundException("No resource " + getName() + + " on Ant's classpath"); + } + } else { + inputStream = cl.getResourceAsStream(getName()); + if (inputStream == null) { + throw new FileNotFoundException("No resource " + getName() + + " on the classpath " + cl); + } + } + return inputStream; } /**