Browse Source

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
master
Steve Loughran 16 years ago
parent
commit
be90dbd7b5
1 changed files with 16 additions and 2 deletions
  1. +16
    -2
      src/main/org/apache/tools/ant/types/resources/JavaResource.java

+ 16
- 2
src/main/org/apache/tools/ant/types/resources/JavaResource.java View File

@@ -17,6 +17,7 @@
*/ */
package org.apache.tools.ant.types.resources; package org.apache.tools.ant.types.resources;


import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;


@@ -53,8 +54,21 @@ public class JavaResource extends AbstractClasspathResource {
* @throws IOException if an error occurs. * @throws IOException if an error occurs.
*/ */
protected InputStream openInputStream(ClassLoader cl) throws IOException { 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;
} }


/** /**


Loading…
Cancel
Save