Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2078687 | 1.3.0 | Jeff Suttor | P3 | Resolved | Fixed | 1.3 |
Name: erR10175 Date: 12/25/2003
The following methods of the class javax.xml.Version
public final String getImplementationTitle()
public final String getImplementationURL()
public final String getImplementationVendor()
public final String getImplementationVendorID()
public final String getImplementationVersion()
returns non-null values if the current class loader cannot find resource
META-INF/services/javax.xml.AbstractVersion.
Javadoc of the class specifies the only way to get the implementation version
information:
"Implementation version information is defined by querying the service provider
as defined in META-INF/services/javax.xml.AbstractVersion. The service provider
must extend javax.xml.AbstractVersion."
So, if the resource META-INF/services/javax.xml.AbstractVersion is not exist,
the methods are specified to return null. But the RI returns some info as if the
resource is available. (Sources of the class Version show that the class
VersionImpl is used in that case).
This bug affects new tests in JCK 1.5 (not integrated yet)
api/javax_xml/Version/index.html#Version[GetImplementationTitle002]
api/javax_xml/Version/index.html#Version[GetImplementationURL002]
api/javax_xml/Version/index.html#Version[GetImplementationVendor002]
api/javax_xml/Version/index.html#Version[GetImplementationVendorID002]
api/javax_xml/Version/index.html#Version[GetImplementationVersion002]
The bug is found in jdk1.5.0/beta/b32.
To reproduce the bug compile and run the following code as shown
in the log below:
------------------------------------------ test.java
import javax.xml.Version;
import java.io.InputStream;
import java.io.IOException;
import java.net.URL;
class test {
static final String VERSION_INFO = "META-INF/services/javax.xml.AbstractVersion";
/**
* Returns a Version that is loaded as if no
* VERSION_INFO is found.
*/
static Object getBlindVersion()
throws ClassNotFoundException, InstantiationException, IllegalAccessException {
return
new ClassLoader(test.class.getClassLoader()) {
public InputStream getResourceAsStream(String name) {
if (VERSION_INFO.equals(name)) {
return null;
}
ClassLoader parent = getParent();
if (parent == null) {
return getSystemResourceAsStream(name);
} else {
return parent.getResourceAsStream(name);
}
}
public URL getResource(String name) {
if (VERSION_INFO.equals(name)) {
return null;
}
ClassLoader parent = getParent();
if (parent == null) {
return getSystemResource(name);
} else {
return parent.getResource(name);
}
}
private byte[] loadClassData(String name) throws ClassNotFoundException {
ClassLoader parent = getParent();
InputStream s = null;
if (parent == null) {
s = getSystemResourceAsStream(name);
} else {
s = parent.getResourceAsStream(name);
}
byte[] buffer = new byte[0];
byte[] chunk = new byte[4096];
int count;
try {
while ((count = s.read(chunk)) >= 0) {
byte[] t = new byte[buffer.length + count];
System.arraycopy(buffer, 0, t, 0, buffer.length);
System.arraycopy(chunk, 0, t, buffer.length, count);
buffer = t;
}
s.close();
}
catch (IOException e) {
throw new ClassNotFoundException(name);
}
return buffer;
}
public Class loadClass(String name) throws ClassNotFoundException {
if ("javax.xml.Version".equals(name)) {
if (name.charAt(0) == '.') {
throw new SecurityException("Absolute package name");
}
if (name.indexOf("..") != -1) {
throw new SecurityException("Illegal package name");
}
Class c = null;
try {
String path = name.replace('.', '/') + ".class";
byte [] data = loadClassData(path);
c = defineClass(name, data, 0, data.length);
} catch (ClassFormatError ex) {
throw new ClassNotFoundException(name);
}
return c;
}
ClassLoader parent = getParent();
if (parent == null) {
return findSystemClass(name);
} else {
return parent.loadClass(name);
}
}
}.loadClass("javax.xml.Version").newInstance();
}
public static void main(String [] args) throws Exception {
Object blindVersion = getBlindVersion();
Object result = blindVersion.getClass()
.getMethod("getImplementationTitle", null)
.invoke(blindVersion, null);
if (result != null) {
System.out.println("Failed: "
+ "version.getImplementationTitle() returns: '"
+ result + "', but expected null");
} else {
System.out.println("OK");
}
}
}
----------------------------------------------------
------------------------------------------------ log
$javac test.java && java -cp . -showversion test
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32, mixed mode)
Failed: version.getImplementationTitle() returns: 'Java API for XML Processing 1.3', but expected null
----------------------------------------------------
======================================================================
The following methods of the class javax.xml.Version
public final String getImplementationTitle()
public final String getImplementationURL()
public final String getImplementationVendor()
public final String getImplementationVendorID()
public final String getImplementationVersion()
returns non-null values if the current class loader cannot find resource
META-INF/services/javax.xml.AbstractVersion.
Javadoc of the class specifies the only way to get the implementation version
information:
"Implementation version information is defined by querying the service provider
as defined in META-INF/services/javax.xml.AbstractVersion. The service provider
must extend javax.xml.AbstractVersion."
So, if the resource META-INF/services/javax.xml.AbstractVersion is not exist,
the methods are specified to return null. But the RI returns some info as if the
resource is available. (Sources of the class Version show that the class
VersionImpl is used in that case).
This bug affects new tests in JCK 1.5 (not integrated yet)
api/javax_xml/Version/index.html#Version[GetImplementationTitle002]
api/javax_xml/Version/index.html#Version[GetImplementationURL002]
api/javax_xml/Version/index.html#Version[GetImplementationVendor002]
api/javax_xml/Version/index.html#Version[GetImplementationVendorID002]
api/javax_xml/Version/index.html#Version[GetImplementationVersion002]
The bug is found in jdk1.5.0/beta/b32.
To reproduce the bug compile and run the following code as shown
in the log below:
------------------------------------------ test.java
import javax.xml.Version;
import java.io.InputStream;
import java.io.IOException;
import java.net.URL;
class test {
static final String VERSION_INFO = "META-INF/services/javax.xml.AbstractVersion";
/**
* Returns a Version that is loaded as if no
* VERSION_INFO is found.
*/
static Object getBlindVersion()
throws ClassNotFoundException, InstantiationException, IllegalAccessException {
return
new ClassLoader(test.class.getClassLoader()) {
public InputStream getResourceAsStream(String name) {
if (VERSION_INFO.equals(name)) {
return null;
}
ClassLoader parent = getParent();
if (parent == null) {
return getSystemResourceAsStream(name);
} else {
return parent.getResourceAsStream(name);
}
}
public URL getResource(String name) {
if (VERSION_INFO.equals(name)) {
return null;
}
ClassLoader parent = getParent();
if (parent == null) {
return getSystemResource(name);
} else {
return parent.getResource(name);
}
}
private byte[] loadClassData(String name) throws ClassNotFoundException {
ClassLoader parent = getParent();
InputStream s = null;
if (parent == null) {
s = getSystemResourceAsStream(name);
} else {
s = parent.getResourceAsStream(name);
}
byte[] buffer = new byte[0];
byte[] chunk = new byte[4096];
int count;
try {
while ((count = s.read(chunk)) >= 0) {
byte[] t = new byte[buffer.length + count];
System.arraycopy(buffer, 0, t, 0, buffer.length);
System.arraycopy(chunk, 0, t, buffer.length, count);
buffer = t;
}
s.close();
}
catch (IOException e) {
throw new ClassNotFoundException(name);
}
return buffer;
}
public Class loadClass(String name) throws ClassNotFoundException {
if ("javax.xml.Version".equals(name)) {
if (name.charAt(0) == '.') {
throw new SecurityException("Absolute package name");
}
if (name.indexOf("..") != -1) {
throw new SecurityException("Illegal package name");
}
Class c = null;
try {
String path = name.replace('.', '/') + ".class";
byte [] data = loadClassData(path);
c = defineClass(name, data, 0, data.length);
} catch (ClassFormatError ex) {
throw new ClassNotFoundException(name);
}
return c;
}
ClassLoader parent = getParent();
if (parent == null) {
return findSystemClass(name);
} else {
return parent.loadClass(name);
}
}
}.loadClass("javax.xml.Version").newInstance();
}
public static void main(String [] args) throws Exception {
Object blindVersion = getBlindVersion();
Object result = blindVersion.getClass()
.getMethod("getImplementationTitle", null)
.invoke(blindVersion, null);
if (result != null) {
System.out.println("Failed: "
+ "version.getImplementationTitle() returns: '"
+ result + "', but expected null");
} else {
System.out.println("OK");
}
}
}
----------------------------------------------------
------------------------------------------------ log
$javac test.java && java -cp . -showversion test
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32, mixed mode)
Failed: version.getImplementationTitle() returns: 'Java API for XML Processing 1.3', but expected null
----------------------------------------------------
======================================================================
- backported by
-
JDK-2078687 javax.xml.Version uses unspecified way to get info
- Resolved