changeset 56:dbba306c0a08

meth: add fix for 7016250
author jrose
date Fri, 22 Apr 2011 01:53:20 -0700
parents bca37faeae55
children 14ffe87f27c6
files netbeans/meth/nbproject/build-impl.xml netbeans/meth/nbproject/genfiles.properties netbeans/meth/nbproject/project.properties netbeans/meth/test/sun/invoke/util/ValueConversionsTest.java
diffstat 4 files changed, 109 insertions(+), 76 deletions(-) [+]
line wrap: on
line diff
--- a/netbeans/meth/nbproject/build-impl.xml	Mon Apr 04 15:23:44 2011 -0700
+++ b/netbeans/meth/nbproject/build-impl.xml	Fri Apr 22 01:53:20 2011 -0700
@@ -704,7 +704,7 @@
     </target>
     <target depends="init" if="do.archive" name="-do-jar-with-libraries-create-manifest" unless="manifest.available">
         <tempfile deleteonexit="true" destdir="${build.dir}" property="tmp.manifest.file"/>
-        <touch file="${tmp.manifest.file}"/>
+        <touch file="${tmp.manifest.file}" verbose="false"/>
     </target>
     <target depends="init" if="do.archive+manifest.available" name="-do-jar-with-libraries-copy-manifest">
         <tempfile deleteonexit="true" destdir="${build.dir}" property="tmp.manifest.file"/>
--- a/netbeans/meth/nbproject/genfiles.properties	Mon Apr 04 15:23:44 2011 -0700
+++ b/netbeans/meth/nbproject/genfiles.properties	Fri Apr 22 01:53:20 2011 -0700
@@ -1,5 +1,5 @@
 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
 # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
 nbproject/build-impl.xml.data.CRC32=a09bc78f
-nbproject/build-impl.xml.script.CRC32=c7189bcb
-nbproject/build-impl.xml.stylesheet.CRC32=19debb58@1.42.1.45
+nbproject/build-impl.xml.script.CRC32=ee4e6a54
+nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45
--- a/netbeans/meth/nbproject/project.properties	Mon Apr 04 15:23:44 2011 -0700
+++ b/netbeans/meth/nbproject/project.properties	Fri Apr 22 01:53:20 2011 -0700
@@ -13,6 +13,8 @@
 javac.processorpath=\
     ${javac.classpath}
   libs.junit_4.classpath=${file.reference.env-folder}/JUNIT4_JAR
+main.class=org.junit.runner.JUnitCore
+mkdist.disabled=false
   platforms.JDK_7X.home=${file.reference.env-folder}/JAVA7X_HOME
 
 # Possible overrides:
@@ -53,7 +55,8 @@
 includes=java/dyn/**/*.java,sun/dyn/**/*.java,test/java/dyn/**/*.java,java/lang/invoke/**/*.java,sun/invoke/**/*.java,test/java/lang/invoke/**/*.java,java/lang/BootstrapMethodError.java,java/lang/ClassValue.java,java/lang/IllegalAccessException.java,java/lang/NoSuchMethodException.java,java/lang/NoSuchFieldException.java
 #includes=**
 jar.compress=true
-javac.classpath=
+javac.classpath=\
+    ${libs.junit_4.classpath}
 #    ${file.reference.bsd-i586-classes}
 # Space-separated list of extra javac options
 javac.compilerargs= -Xbootclasspath/p:${build.classes.dir} -Xlint:none ${javac.standalone.bcp}
--- a/netbeans/meth/test/sun/invoke/util/ValueConversionsTest.java	Mon Apr 04 15:23:44 2011 -0700
+++ b/netbeans/meth/test/sun/invoke/util/ValueConversionsTest.java	Fri Apr 22 01:53:20 2011 -0700
@@ -39,51 +39,82 @@
 
     @Test
     public void testUnbox() throws Throwable {
-        System.out.println("unbox");
-        for (Wrapper w : Wrapper.values()) {
-            System.out.println(w);
-            boolean exact = (w == Wrapper.SHORT);  // spot-check exact typing version
+        testUnbox(false);
+    }
+
+    @Test
+    public void testUnboxCast() throws Throwable {
+        testUnbox(true);
+    }
+
+    private void testUnbox(boolean doCast) throws Throwable {
+        //System.out.println("unbox");
+        for (Wrapper dst : Wrapper.values()) {
+            //System.out.println(dst);
+            for (Wrapper src : Wrapper.values()) {
+                testUnbox(doCast, dst, src);
+            }
+        }
+    }
+
+    private void testUnbox(boolean doCast, Wrapper dst, Wrapper src) throws Throwable {
+        boolean expectThrow = !doCast && !dst.isConvertibleFrom(src);
+        if (dst == Wrapper.OBJECT || src == Wrapper.OBJECT)  return;  // must have prims
+        if (dst == Wrapper.OBJECT)
+            expectThrow = false;  // everything (even VOID==null here) converts to OBJECT
+        try {
             for (int n = -5; n < 10; n++) {
-                Object box = w.wrap(n);
-                switch (w) {
+                Object box = src.wrap(n);
+                switch (src) {
                     case VOID:   assertEquals(box, null); break;
-                    case OBJECT: assertEquals(box.getClass(), Integer.class); break;
+                    case OBJECT: box = box.toString(); break;
                     case SHORT:  assertEquals(box.getClass(), Short.class); break;
-                    default:     assertEquals(box.getClass(), w.wrapperType()); break;
+                    default:     assertEquals(box.getClass(), src.wrapperType()); break;
                 }
-                MethodHandle unboxer = ValueConversions.unbox(w.primitiveType(), exact);
-                Object expResult = box;
+                MethodHandle unboxer;
+                if (doCast)
+                    unboxer = ValueConversions.unboxCast(dst.primitiveType());
+                else
+                    unboxer = ValueConversions.unbox(dst.primitiveType());
+                Object expResult = (box == null) ? dst.zero() : dst.wrap(box);
                 Object result = null;
-                switch (w) {
+                switch (dst) {
                     case INT:     result = (int)     unboxer.invokeExact(box); break;
                     case LONG:    result = (long)    unboxer.invokeExact(box); break;
                     case FLOAT:   result = (float)   unboxer.invokeExact(box); break;
                     case DOUBLE:  result = (double)  unboxer.invokeExact(box); break;
                     case CHAR:    result = (char)    unboxer.invokeExact(box); break;
                     case BYTE:    result = (byte)    unboxer.invokeExact(box); break;
-                    case SHORT:   result = (short)   unboxer.invokeExact((Short)box); break;
+                    case SHORT:   result = (short)   unboxer.invokeExact(box); break;
                     case OBJECT:  result = (Object)  unboxer.invokeExact(box); break;
                     case BOOLEAN: result = (boolean) unboxer.invokeExact(box); break;
                     case VOID:    result = null;     unboxer.invokeExact(box); break;
                 }
-                assertEquals("w="+w+" n="+n+" box="+box, expResult, result);
+                if (expectThrow) {
+                    expResult = "(need an exception)";
+                }
+                assertEquals("(doCast,expectThrow,dst,src,n,box)="+Arrays.asList(doCast,expectThrow,dst,src,n,box),
+                             expResult, result);
             }
+        } catch (RuntimeException ex) {
+            if (expectThrow)  return;
+            System.out.println("Unexpected throw for (doCast,expectThrow,dst,src)="+Arrays.asList(doCast,expectThrow,dst,src));
+            throw ex;
         }
     }
 
     @Test
     public void testUnboxRaw() throws Throwable {
-        System.out.println("unboxRaw");
+        //System.out.println("unboxRaw");
         for (Wrapper w : Wrapper.values()) {
             if (w == Wrapper.OBJECT)  continue;  // skip this; no raw form
-            boolean exact = (w == Wrapper.SHORT);  // spot-check exact typing version
-            System.out.println(w);
+            //System.out.println(w);
             for (int n = -5; n < 10; n++) {
                 Object box = w.wrap(n);
                 long expResult = w.unwrapRaw(box);
                 Object box2 = w.wrapRaw(expResult);
                 assertEquals(box, box2);
-                MethodHandle unboxer = ValueConversions.unboxRaw(w.primitiveType(), exact);
+                MethodHandle unboxer = ValueConversions.unboxRaw(w.primitiveType());
                 long result = -1;
                 switch (w) {
                     case INT:     result = (int)  unboxer.invokeExact(box); break;
@@ -92,110 +123,111 @@
                     case DOUBLE:  result = (long) unboxer.invokeExact(box); break;
                     case CHAR:    result = (int)  unboxer.invokeExact(box); break;
                     case BYTE:    result = (int)  unboxer.invokeExact(box); break;
-                    case SHORT:   result = (int)  unboxer.invokeExact((Short)box); break;
+                    case SHORT:   result = (int)  unboxer.invokeExact(box); break;
                     case BOOLEAN: result = (int)  unboxer.invokeExact(box); break;
                     case VOID:    result = (int)  unboxer.invokeExact(box); break;
                 }
-                assertEquals("w="+w+" n="+n+" box="+box, expResult, result);
+                assertEquals("(w,n,box)="+Arrays.asList(w,n,box),
+                             expResult, result);
             }
         }
     }
 
     @Test
     public void testBox() throws Throwable {
-        System.out.println("box");
+        //System.out.println("box");
         for (Wrapper w : Wrapper.values()) {
             if (w == Wrapper.VOID)  continue;  // skip this; no unboxed form
-            boolean exact = (w != Wrapper.SHORT);  // spot-check exact typing version
-            System.out.println(w);
+            //System.out.println(w);
             for (int n = -5; n < 10; n++) {
                 Object box = w.wrap(n);
-                MethodHandle boxer = ValueConversions.box(w.primitiveType(), exact);
+                MethodHandle boxer = ValueConversions.box(w.primitiveType());
                 Object expResult = box;
                 Object result = null;
                 switch (w) {
-                    case INT:     result = (Integer)   boxer.invokeExact((int)n); break;
-                    case LONG:    result = (Long)      boxer.invokeExact((long)n); break;
-                    case FLOAT:   result = (Float)     boxer.invokeExact((float)n); break;
-                    case DOUBLE:  result = (Double)    boxer.invokeExact((double)n); break;
-                    case CHAR:    result = (Character) boxer.invokeExact((char)n); break;
-                    case BYTE:    result = (Byte)      boxer.invokeExact((byte)n); break;
-                    case SHORT:   result = (Object)    boxer.invokeExact((short)n); break;
-                    case OBJECT:  result = (Object)    boxer.invokeExact((Object)n); break;
-                    case BOOLEAN: result = (Boolean)   boxer.invokeExact(n != 0); break;
+                    case INT:     result = boxer.invokeExact((int)n); break;
+                    case LONG:    result = boxer.invokeExact((long)n); break;
+                    case FLOAT:   result = boxer.invokeExact((float)n); break;
+                    case DOUBLE:  result = boxer.invokeExact((double)n); break;
+                    case CHAR:    result = boxer.invokeExact((char)n); break;
+                    case BYTE:    result = boxer.invokeExact((byte)n); break;
+                    case SHORT:   result = boxer.invokeExact((short)n); break;
+                    case OBJECT:  result = boxer.invokeExact((Object)n); break;
+                    case BOOLEAN: result = boxer.invokeExact((n & 1) != 0); break;
                 }
-                assertEquals("w="+w+" n="+n+" box="+box, expResult, result);
+                assertEquals("(dst,src,n,box)="+Arrays.asList(w,w,n,box),
+                             expResult, result);
             }
         }
     }
 
     @Test
     public void testBoxRaw() throws Throwable {
-        System.out.println("boxRaw");
+        //System.out.println("boxRaw");
         for (Wrapper w : Wrapper.values()) {
             if (w == Wrapper.VOID)  continue;  // skip this; no unboxed form
             if (w == Wrapper.OBJECT)  continue;  // skip this; no raw form
-            boolean exact = (w != Wrapper.SHORT);  // spot-check exact typing version
-            System.out.println(w);
+            //System.out.println(w);
             for (int n = -5; n < 10; n++) {
                 Object box = w.wrap(n);
                 long   raw = w.unwrapRaw(box);
                 Object expResult = box;
-                MethodHandle boxer = ValueConversions.boxRaw(w.primitiveType(), exact);
+                MethodHandle boxer = ValueConversions.boxRaw(w.primitiveType());
                 Object result = null;
                 switch (w) {
-                case INT:     result = (Integer)   boxer.invokeExact((int)raw); break;
-                case LONG:    result = (Long)      boxer.invokeExact(raw); break;
-                case FLOAT:   result = (Float)     boxer.invokeExact((int)raw); break;
-                case DOUBLE:  result = (Double)    boxer.invokeExact(raw); break;
-                case CHAR:    result = (Character) boxer.invokeExact((int)raw); break;
-                case BYTE:    result = (Byte)      boxer.invokeExact((int)raw); break;
-                case SHORT:   result = (Object)    boxer.invokeExact((int)raw); break;
-                case BOOLEAN: result = (Boolean)   boxer.invokeExact((int)raw); break;
+                case INT:     result = boxer.invokeExact((int)raw); break;
+                case LONG:    result = boxer.invokeExact(raw); break;
+                case FLOAT:   result = boxer.invokeExact((int)raw); break;
+                case DOUBLE:  result = boxer.invokeExact(raw); break;
+                case CHAR:    result = boxer.invokeExact((int)raw); break;
+                case BYTE:    result = boxer.invokeExact((int)raw); break;
+                case SHORT:   result = boxer.invokeExact((int)raw); break;
+                case BOOLEAN: result = boxer.invokeExact((int)raw); break;
                 }
-                assertEquals("w="+w+" n="+n+" box="+box, expResult, result);
+                assertEquals("(dst,src,n,box)="+Arrays.asList(w,w,n,box),
+                             expResult, result);
             }
         }
     }
 
     @Test
     public void testReboxRaw() throws Throwable {
-        System.out.println("reboxRaw");
+        //System.out.println("reboxRaw");
         for (Wrapper w : Wrapper.values()) {
             Wrapper pw = Wrapper.forPrimitiveType(w.rawPrimitiveType());
             if (w == Wrapper.VOID)  continue;  // skip this; no unboxed form
             if (w == Wrapper.OBJECT)  continue;  // skip this; no raw form
-            boolean exact = (w != Wrapper.SHORT);  // spot-check exact typing version
-            System.out.println(w);
+            //System.out.println(w);
             for (int n = -5; n < 10; n++) {
                 Object box = w.wrap(n);
                 Object raw = pw.wrap(w.unwrapRaw(box));
                 Object expResult = box;
-                MethodHandle boxer = ValueConversions.rebox(w.primitiveType(), exact);
+                MethodHandle boxer = ValueConversions.rebox(w.primitiveType());
                 Object result = null;
                 switch (w) {
-                case INT:     result = (Integer)   boxer.invokeExact(raw); break;
-                case LONG:    result = (Long)      boxer.invokeExact(raw); break;
-                case FLOAT:   result = (Float)     boxer.invokeExact(raw); break;
-                case DOUBLE:  result = (Double)    boxer.invokeExact(raw); break;
-                case CHAR:    result = (Character) boxer.invokeExact(raw); break;
-                case BYTE:    result = (Byte)      boxer.invokeExact(raw); break;
-                case SHORT:   result = (Object)    boxer.invokeExact(raw); break;
-                case BOOLEAN: result = (Boolean)   boxer.invokeExact(raw); break;
+                case INT:     result = boxer.invokeExact(raw); break;
+                case LONG:    result = boxer.invokeExact(raw); break;
+                case FLOAT:   result = boxer.invokeExact(raw); break;
+                case DOUBLE:  result = boxer.invokeExact(raw); break;
+                case CHAR:    result = boxer.invokeExact(raw); break;
+                case BYTE:    result = boxer.invokeExact(raw); break;
+                case SHORT:   result = boxer.invokeExact(raw); break;
+                case BOOLEAN: result = boxer.invokeExact(raw); break;
                 }
-                assertEquals("w="+w+" n="+n+" box="+box, expResult, result);
+                assertEquals("(dst,src,n,box)="+Arrays.asList(w,w,n,box),
+                             expResult, result);
             }
         }
     }
 
     @Test
     public void testCast() throws Throwable {
-        System.out.println("cast");
+        //System.out.println("cast");
         Class<?>[] types = { Object.class, Serializable.class, String.class, Number.class, Integer.class };
         Object[] objects = { new Object(), Boolean.FALSE,      "hello",      (Long)12L,    (Integer)6    };
         for (Class<?> dst : types) {
-            boolean exactInt = (dst == Integer.class);
-            MethodHandle caster = ValueConversions.cast(dst, exactInt);
+            MethodHandle caster = ValueConversions.cast(dst);
+            assertEquals(caster.type(), ValueConversions.identity().type());
             for (Object obj : objects) {
                 Class<?> src = obj.getClass();
                 boolean canCast;
@@ -207,11 +239,7 @@
                 }
                 //System.out.println("obj="+obj+" <: dst="+dst);
                 try {
-                    Object result;
-                    if (!exactInt)
-                        result = caster.invokeExact(obj);
-                    else
-                        result = (Integer) caster.invokeExact(obj);
+                    Object result = caster.invokeExact(obj);
                     if (canCast)
                         assertEquals(obj, result);
                     else
@@ -226,7 +254,7 @@
 
     @Test
     public void testIdentity() throws Throwable {
-        System.out.println("identity");
+        //System.out.println("identity");
         MethodHandle id = ValueConversions.identity();
         Object expResult = "foo";
         Object result = id.invokeExact(expResult);
@@ -236,8 +264,9 @@
 
     @Test
     public void testVarargsArray() throws Throwable {
-        System.out.println("varargsArray");
-        for (int nargs = 0; nargs <= 5; nargs++) {
+        //System.out.println("varargsArray");
+        for (int nargs = 0; nargs <= 250; nargs += 1+(nargs/17)) {
+            if (nargs > 9)  break;  // FIXME
             MethodHandle target = ValueConversions.varargsArray(nargs);
             Object[] args = new Object[nargs];
             for (int i = 0; i < nargs; i++)
@@ -249,8 +278,9 @@
 
     @Test
     public void testVarargsList() throws Throwable {
-        System.out.println("varargsList");
-        for (int nargs = 0; nargs <= 5; nargs++) {
+        //System.out.println("varargsList");
+        for (int nargs = 0; nargs <= 250; nargs += 1+(nargs/17)) {
+            if (nargs > 9)  break;  // FIXME
             MethodHandle target = ValueConversions.varargsList(nargs);
             Object[] args = new Object[nargs];
             for (int i = 0; i < nargs; i++)