-
Bug
-
Resolution: Fixed
-
P2
-
5.0
-
b81
-
generic
-
generic
After fix of CR 6215975 "FindClass documentation clarification" in Mustang
the updated JNI specification states the following for FindClass function:
---Excerpt-from-spec---
jclass FindClass(JNIEnv *env, const char *name);
This function loads a locally-defined class. It searches the directories
and zip files specified by the CLASSPATH environment variable for the class
with the specified name.
The name argument is a class descriptor ( §12.3.2). For example, the descriptor
for the java.lang.String class is:
"java/lang/String"
The descriptor of the array class java.lang.Object[] is:
"[Ljava/lang/Object;"
---End-of-excerpt---
However, Sun's JDK (at least 5.0/6.0) permits "Lcom/test/test/Test;"
as name parameter for FindClass, though the name is incorrect here according
to both updated/1.5 JNI specs (for FindClass):
http://download.java.net/jdk6/doc/guide/jni/spec/functions.html
and JVMS (Chapter 4.2, "The Internal Form of Fully Qualified Class and Interface Names"):
http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#14757
We believe that:
- either JNI spec should clearly describe that "Lcom/test/test/Test;" is a valid
class descriptor name for the com.test.test.Test class, or
- implementation should be fixed and not accept such names.
Minimized test:
===============
--- com/test/test/Test.java ---
package com.test.test;
public class Test {
static {
System.loadLibrary("test");
}
public static native void check();
public static void main(String[] args) {
try {
Test.check();
System.out.println("FAILED");
} catch (java.lang.NoClassDefFoundError e) {
System.out.println("PASSED");
}
}
}
--- com/test/test/Test.java ---
--- Test.c ---
#include <jni.h>
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT void JNICALL Java_com_test_test_Test_check
(JNIEnv *env, jclass clazz)
{
jclass cl;
cl = (*env)->FindClass(env, "Lcom/test/test/Test;");
if(cl == NULL)
{
printf("OKAY, could not find class: cl = NULL\n");
} else
{
printf("Oops, class is found\n");
}
}
#ifdef __cplusplus
}
#endif
--- Test.c ---
--- compile.sh ---
JDK=/set/java/re/jdk/1.5.0/latest/binaries/solaris-sparc
gcc -fPIC -shared -o ./libtest.so -I${JDK}/include -I${JDK}/include/solaris ./Test.c
--- compile.sh ---
=====================
Minimized test output:
=====================
<yg153347@d-espb04-125-31> pwd
/home/yg153347/tmp
<yg153347@d-espb04-125-31> javac -classpath . com/test/test/Test.java
<yg153347@d-espb04-125-31> ./compile.sh
<yg153347@d-espb04-125-31> java -showversion -classpath . com.test.test.Test
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)
Oops, class is found
FAILED
=====================
Specific Machine Info:
=====================
<yg153347@d-espb04-125-31> uname -a
SunOS d-espb04-125-31 5.9 Generic_117171-09 sun4u sparc SUNW,Ultra-60
the updated JNI specification states the following for FindClass function:
---Excerpt-from-spec---
jclass FindClass(JNIEnv *env, const char *name);
This function loads a locally-defined class. It searches the directories
and zip files specified by the CLASSPATH environment variable for the class
with the specified name.
The name argument is a class descriptor ( §12.3.2). For example, the descriptor
for the java.lang.String class is:
"java/lang/String"
The descriptor of the array class java.lang.Object[] is:
"[Ljava/lang/Object;"
---End-of-excerpt---
However, Sun's JDK (at least 5.0/6.0) permits "Lcom/test/test/Test;"
as name parameter for FindClass, though the name is incorrect here according
to both updated/1.5 JNI specs (for FindClass):
http://download.java.net/jdk6/doc/guide/jni/spec/functions.html
and JVMS (Chapter 4.2, "The Internal Form of Fully Qualified Class and Interface Names"):
http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#14757
We believe that:
- either JNI spec should clearly describe that "Lcom/test/test/Test;" is a valid
class descriptor name for the com.test.test.Test class, or
- implementation should be fixed and not accept such names.
Minimized test:
===============
--- com/test/test/Test.java ---
package com.test.test;
public class Test {
static {
System.loadLibrary("test");
}
public static native void check();
public static void main(String[] args) {
try {
Test.check();
System.out.println("FAILED");
} catch (java.lang.NoClassDefFoundError e) {
System.out.println("PASSED");
}
}
}
--- com/test/test/Test.java ---
--- Test.c ---
#include <jni.h>
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT void JNICALL Java_com_test_test_Test_check
(JNIEnv *env, jclass clazz)
{
jclass cl;
cl = (*env)->FindClass(env, "Lcom/test/test/Test;");
if(cl == NULL)
{
printf("OKAY, could not find class: cl = NULL\n");
} else
{
printf("Oops, class is found\n");
}
}
#ifdef __cplusplus
}
#endif
--- Test.c ---
--- compile.sh ---
JDK=/set/java/re/jdk/1.5.0/latest/binaries/solaris-sparc
gcc -fPIC -shared -o ./libtest.so -I${JDK}/include -I${JDK}/include/solaris ./Test.c
--- compile.sh ---
=====================
Minimized test output:
=====================
<yg153347@d-espb04-125-31> pwd
/home/yg153347/tmp
<yg153347@d-espb04-125-31> javac -classpath . com/test/test/Test.java
<yg153347@d-espb04-125-31> ./compile.sh
<yg153347@d-espb04-125-31> java -showversion -classpath . com.test.test.Test
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)
Oops, class is found
FAILED
=====================
Specific Machine Info:
=====================
<yg153347@d-espb04-125-31> uname -a
SunOS d-espb04-125-31 5.9 Generic_117171-09 sun4u sparc SUNW,Ultra-60
- relates to
-
JDK-6215975 FindClass documentation clarification
-
- Closed
-
-
JDK-6411605 JNI FindClass accepts class descriptors in signature form
-
- Closed
-