JDK-4339315 : Using an underscore in a class name causes problems with JNI and javah
  • Type: Bug
  • Component: tools
  • Sub-Component: javah
  • Affected Version: 1.2.1_03
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2000-05-18
  • Updated: 2002-05-13
  • Resolved: 2002-05-13
Related Reports
Duplicate :  
Description

Name: skT45625			Date: 05/18/2000


Classic VM (build JDK-1.2.2-001, native threads, symcjit)
AND ALSO
Solaris VM (build Solaris_JDK1.2.2_05a, native threads, sunwjit)

Step 1. create some java file with an underscore in the class name.

/** get_string.java file **/
class get_string
{
   /** native method that performs the UNIX function getcwd. **/
   private native String get_string(int size);

   public static void main(String args[])
   {
      int size_t = 64;

      get_string cw = new get_string();

      System.out.println("String returned = " + cw.get_string(size_t));
   }


   static {
      System.loadLibrary("get_string");
   }
}


Step 2. Execute javac get_string.java
Step 3. Execute javah -jni get_string
        The file generated is get_0005fstring.h shown below.

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class get_0005fstring */

#ifndef _Included_get_0005fstring
#define _Included_get_0005fstring
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     get_0005fstring
 * Method:    get_string
 * Signature: (I)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_get_1string_get_1string
  (JNIEnv *, jobject, jint);

#ifdef __cplusplus
}
#endif
#endif
~

The obvious problem is the 0005f being inserted into the middle of the file
name, which incidentally is the unicode char for an underscore.  The less
obvious problem is the name of the native method has had the "1" character
inserted after each underscore....JNIEXPORT jstring JNICALL
Java_get_1string_get_1string.

This is a very large problem for us.  We have a nightly build cycle and
removing the erroneous characters manually is not an option.  When the problem
gets fixed in javah all of the native interface code will have to be touched to
remove the erroneous characters.
(Review ID: 105002) 
======================================================================

Comments
EVALUATION This is broken in JDK 1.4.1 b11 as well.. ###@###.### 2002-05-13
13-05-2002