United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7129034 VM crash with a field setter method with a filterArguments
JDK-7129034 : VM crash with a field setter method with a filterArguments

Details
Type:
Bug
Submit Date:
2012-01-11
Status:
Closed
Updated Date:
2013-10-16
Project Name:
JDK
Resolved Date:
2013-10-16
Component:
core-libs
OS:
generic
Sub-Component:
java.lang.invoke
CPU:
generic
Priority:
P3
Resolution:
Cannot Reproduce
Affected Versions:
7,8
Fixed Versions:
8

Related Reports
Backport:
Backport:
Relates:

Sub Tasks

Description
The following test program crashes the VM.

----

import java.lang.invoke.*;
import java.lang.reflect.*;

public class Test {
    public Test obj;
    public String str;

    public static void main(String[] args) throws Throwable {
        MethodHandles.Lookup l = MethodHandles.publicLookup();
        Field field = Test.class.getField("str");
        MethodHandle mh = l.unreflectSetter(field);
        MethodHandle filter = l.unreflectGetter(Test.class.getField("obj"));
        mh = MethodHandles.filterArguments(mh, 0, filter);
        mh.invokeExact(new Test(), "hello");
    }
}

---

The test crashes with the problematic frame "Unsafe_setObject". Without the filterArguments, if 'null' is directly passed to invokeExact as first argument, then we get WrongTypeException because null is inferred as Void type. But, when filterArguments and the filter returns null value, then the VM crashes.

                                    

Comments
EVALUATION

Missing null check in FieldAccessor.setFieldL, etc.
                                     
2012-02-10
SUGGESTED FIX

src/share/classes/java/lang/invoke/MethodHandleImpl.java

+        private static void nullCheck(Object obj) { obj.getClass(); }

-        int getFieldI(Object /*C*/ obj) { return unsafe.getInt(obj, offset); }
+        int getFieldI(Object /*C*/ obj) { nullCheck(obj); return unsafe.getInt(obj, offset); }

etc.
                                     
2012-02-10
EVALUATION

http://hg.openjdk.java.net/hsx/hotspot-main/jdk/rev/beeb1d5ecd9e
                                     
2012-08-11
Doesn't happen with 7u45 or 8.
                                     
2013-10-16



Hardware and Software, Engineered to Work Together