8013167: Vararg constructor not found
authorattila
Thu, 25 Apr 2013 15:31:23 +0200
changeset 17247 607f6372b21b
parent 17246 a1bcf4d2bff1
child 17248 60ef2a001ec2
8013167: Vararg constructor not found Reviewed-by: jlaskey, lagergren, sundar
nashorn/src/jdk/internal/dynalink/beans/StaticClassIntrospector.java
nashorn/src/jdk/internal/dynalink/beans/StaticClassLinker.java
nashorn/test/script/basic/JDK-8013167.js
nashorn/test/script/basic/JDK-8013167.js.EXPECTED
nashorn/test/src/jdk/nashorn/test/models/VarArgConstructor.java
--- a/nashorn/src/jdk/internal/dynalink/beans/StaticClassIntrospector.java	Thu Apr 25 14:47:17 2013 +0200
+++ b/nashorn/src/jdk/internal/dynalink/beans/StaticClassIntrospector.java	Thu Apr 25 15:31:23 2013 +0200
@@ -84,10 +84,10 @@
 package jdk.internal.dynalink.beans;
 
 import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
 import java.lang.invoke.MethodType;
 import java.util.HashMap;
 import java.util.Map;
+import jdk.nashorn.internal.lookup.Lookup;
 
 class StaticClassIntrospector extends FacetIntrospector {
     StaticClassIntrospector(Class<?> clazz) {
@@ -98,7 +98,7 @@
     Map<String, MethodHandle> getInnerClassGetters() {
         final Map<String, MethodHandle> map = new HashMap<>();
         for(Class<?> innerClass: membersLookup.getInnerClasses()) {
-            map.put(innerClass.getSimpleName(), editMethodHandle(MethodHandles.constant(StaticClass.class,
+            map.put(innerClass.getSimpleName(), editMethodHandle(Lookup.MH.constant(StaticClass.class,
                     StaticClass.forClass(innerClass))));
         }
         return map;
@@ -106,7 +106,11 @@
 
     @Override
     MethodHandle editMethodHandle(MethodHandle mh) {
-        MethodHandle newHandle = MethodHandles.dropArguments(mh, 0, Object.class);
+        return dropReceiver(mh, Object.class);
+    }
+
+    static MethodHandle dropReceiver(final MethodHandle mh, final Class<?> receiverClass) {
+        MethodHandle newHandle = Lookup.MH.dropArguments(mh, 0, receiverClass);
         // NOTE: this is a workaround for the fact that dropArguments doesn't preserve vararg collector state.
         if(mh.isVarargsCollector() && !newHandle.isVarargsCollector()) {
             final MethodType type = mh.type();
--- a/nashorn/src/jdk/internal/dynalink/beans/StaticClassLinker.java	Thu Apr 25 14:47:17 2013 +0200
+++ b/nashorn/src/jdk/internal/dynalink/beans/StaticClassLinker.java	Thu Apr 25 15:31:23 2013 +0200
@@ -144,7 +144,7 @@
         }
 
         private static MethodHandle drop(MethodHandle mh) {
-            return MethodHandles.dropArguments(mh, 0, StaticClass.class);
+            return StaticClassIntrospector.dropReceiver(mh, StaticClass.class);
         }
 
         @Override
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8013167.js	Thu Apr 25 15:31:23 2013 +0200
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8013167: Vararg constructor was not found
+ *
+ * @test
+ * @run
+ */
+
+var x = new Packages.jdk.nashorn.test.models.VarArgConstructor(1, false, "a", "b", "c")
+print(x.indicator)
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8013167.js.EXPECTED	Thu Apr 25 15:31:23 2013 +0200
@@ -0,0 +1,1 @@
+vararg
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/src/jdk/nashorn/test/models/VarArgConstructor.java	Thu Apr 25 15:31:23 2013 +0200
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.nashorn.test.models;
+
+import java.util.List;
+
+public class VarArgConstructor {
+    private final String indicator;
+
+    public VarArgConstructor(int x, boolean y, List<String> z) {
+        indicator = "non-vararg";
+    }
+
+    public VarArgConstructor(int x, boolean y, String... z) {
+        indicator = "vararg";
+    }
+
+    public String getIndicator() {
+        return indicator;
+    }
+}