This discussion is archived
0 Replies Latest reply: Jul 20, 2012 9:10 AM by 950805 RSS

Problem generating JNI headers with javah and JDK7

950805 Newbie
Currently Being Moderated
I am using JDK 1.7.0_05 (tested on both Windows XP 32-bit and Linux 32-bit Ubuntu 10.04 LTS).

Here is my test code:

*<FILE: Test.java>*
class Test
*{*
public native boolean testNativeMethod(int x, int y);

public class ThisIsATest
*{*
public native void thisIsInnerNative(boolean test);
*}*

*private Thread myThread = new Thread(new Runnable() {*

public native void innerNative();

*public void run() {*
System.out.println("this is a test");
*}*
*});*

public static void main(String[] args)
*{*
System.out.println("This is a test");
*}*
*}*

Here is a summary of my command line work:

+~/jnitest > javac Test.java+
+~/jnitest > ls+
Test$1.class  Test$A.class  Test.class     Test.java

So far, so good.... Now we'll generate JNI headers for the named inner class:

+~/jnitest > javah -jni Test\$A+
+~/jnitest > ls+
Test$1.class  Test$A.class  Test_A.h  Test.class  Test.java

Works just fine. Now for the anonymous inner class:

+~/jnitest > javah -jni Test\$1+
Exception in thread "main" java.lang.IllegalArgumentException: Not a valid class name: Test.1
at com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:177)
at com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:68)
at com.sun.tools.javah.JavahTask.run(JavahTask.java:509)
at com.sun.tools.javah.JavahTask.run(JavahTask.java:335)
at com.sun.tools.javah.Main.main(Main.java:46)

This does not happen with jdk6. This is not a problem with escaping the '$' character in Linux. This happens the same way using a Windows command prompt. Any thoughts? Is this a bug?

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points