Name: smR10189 Date: 03/19/2003
Java 2 Platform SE API specification of the
method ClassLoader.getResourceAsStream() says:
"public InputStream getResourceAsStream(String name)
Returns an input stream for reading the specified resource.
The search order is described in the documentation for getResource(String).
Specification of the method ClassLoader.getResource() says:
"public URL getResource(String name)
This method will first search the parent class loader for the resource;
if the parent is null the path of the class loader built-in to the
virtual machine is searched. That failing, this method will call
findResource to find the resource."
The following issues should be clarified:
- The specification of the method getResource() doesn't
explicitly specify which method of the parent class loader would
be invoked if it's exists.
We can make here an assumption that this method is also getResource().
- The specification of the method getResourceAsStream() only
says that the search order is like in the method getResource().
It is not clear which parent class loader method getResourceAsStream()
or getResource() should be invoked.
The specification may be interpreted in two ways:
1)As the search order is described in the method getResource(), so
all parent's class loader methods to be invoked is the same as for
2)As the method getResource() delegates the resource finding to the
same parent's class loader method then the method getResourceAsStream() also
should delegate the resource finding to the corresponding
method of parent class loader. So, the method getResourceAsStream()
should be invoked.
The specification should explicitly define the method of a parent class
loader to be invoked for the following class loader methods: