JDK-8170063 : Jdk incorrectly process nameless parameters in MethodParameters Attribute
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 8
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2016-11-11
  • Updated: 2016-11-21
  • Resolved: 2016-11-21
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :


ADDITIONAL OS VERSION INFORMATION :
Ubuntu 14.04

A DESCRIPTION OF THE PROBLEM :
Hotspot constucts nameless parameter with empty name ("") that leads to verification error in reflection code (MalformedParametersException in Executable.verifyParameters)

hotspot code in reflection.cpp:
oop Reflection::new_parameter(Handle method, int index, Symbol* sym,
                              int flags, TRAPS) {
  Handle name;

  // A null symbol here translates to the empty string
  if(NULL != sym) {
    name = java_lang_String::create_from_symbol(sym, CHECK_NULL);
  } else {
    name = java_lang_String::create_from_str("", CHECK_NULL);
  }
 ....
}

Verification in Executable.verifyParameters:
...
    if (name != null) {
                if (name.isEmpty() || name.indexOf('.') != -1 ||
                    name.indexOf(';') != -1 || name.indexOf('[') != -1 ||
                    name.indexOf('/') != -1) {
                    throw new MalformedParametersException("Invalid parameter name \"" + name + "\"");
                }
            }
...

NB: there is special workaround in Parameter.getName() with special empty name processing case:
public String getName() {
        // Note: empty strings as paramete names are now outlawed.
        // The .equals("") is for compatibility with current JVM
        // behavior.  It may be removed at some point.
        if(name == null || name.equals(""))
            return "arg" + index;
        else
            return name;
    }


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Generate method parameters metadata with null parameters names and then try to extract them via Method.getParameters()

ACTUAL -
java.lang.reflect.MalformedParametersException: Invalid parameter name ""

REPRODUCIBILITY :
This bug can be reproduced always.


Comments
Closing as duplicate of JDK-8058322
21-11-2016

This is a duplicate of JDK-8058322
21-11-2016

This problem is already handled in JDK-9, below is the code difference. We need to backport this to fix this issue. JDK-9 Handle rh = java_lang_reflect_Parameter::create(CHECK_NULL); if(NULL != sym) { 978 Handle name = java_lang_String::create_from_symbol(sym, CHECK_NULL); 979 java_lang_reflect_Parameter::set_name(rh(), name()); 980 } else { 981 java_lang_reflect_Parameter::set_name(rh(), NULL); 982 } JDK-8u if(NULL != sym) { 874 name = java_lang_String::create_from_symbol(sym, CHECK_NULL); 875 } else { 876 name = java_lang_String::create_from_str("", CHECK_NULL); 877 } 878
21-11-2016