< prev index next >

test/hotspot/jtreg/compiler/jsr292/methodHandleExceptions/TestAMEnotNPE.java

Print this page
rev 50604 : imported patch jep181-rev1
   1 /*
   2  * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @bug 8025260 8016839
  27  * @summary Ensure that AbstractMethodError and IllegalAccessError are thrown appropriately, not NullPointerException
  28  * @modules java.base/jdk.internal.org.objectweb.asm
  29  * @library / .
  30  *
  31  * @build p.*
  32  * @run main/othervm compiler.jsr292.methodHandleExceptions.TestAMEnotNPE
  33  * @run main/othervm -Xint compiler.jsr292.methodHandleExceptions.TestAMEnotNPE
  34  * @run main/othervm -Xcomp compiler.jsr292.methodHandleExceptions.TestAMEnotNPE
  35  */
  36 







  37 package compiler.jsr292.methodHandleExceptions;
  38 
  39 import p.Dok;
  40 import jdk.internal.org.objectweb.asm.ClassWriter;
  41 import jdk.internal.org.objectweb.asm.Handle;
  42 import jdk.internal.org.objectweb.asm.MethodVisitor;
  43 import jdk.internal.org.objectweb.asm.Opcodes;
  44 
  45 import java.lang.reflect.InvocationTargetException;
  46 import java.lang.reflect.Method;
  47 import java.util.ArrayList;
  48 import java.util.List;
  49 
  50 import static jdk.internal.org.objectweb.asm.Opcodes.ACC_PRIVATE;
  51 import static jdk.internal.org.objectweb.asm.Opcodes.ACC_PUBLIC;
  52 import static jdk.internal.org.objectweb.asm.Opcodes.ACC_STATIC;
  53 import static jdk.internal.org.objectweb.asm.Opcodes.ACC_SUPER;
  54 import static jdk.internal.org.objectweb.asm.Opcodes.ALOAD;
  55 import static jdk.internal.org.objectweb.asm.Opcodes.ILOAD;
  56 import static jdk.internal.org.objectweb.asm.Opcodes.INVOKESPECIAL;


  74      * found in the corresponding jar files.
  75      *
  76      * Jarfilenames look something like pD_ext_pF (p.D extends p.F)
  77      * and qD_m_pp_imp_pI (q.D with package-private m implements p.I)
  78      *
  79      */
  80     public static void main(String args[]) throws Throwable {
  81         ArrayList<Throwable> lt = new ArrayList<Throwable>();
  82 
  83         if (args.length > 0) {
  84             String a0 = args[0].toLowerCase();
  85             if (a0.length() > 0) {
  86                 writeJarFiles = ("writejarfiles").startsWith(a0);
  87                 readJarFiles = ("readjarfiles").startsWith(a0);
  88             }
  89             if (!(writeJarFiles || readJarFiles)) {
  90                 throw new Error("Command line parameter (if any) should be prefix of writeJarFiles or readJarFiles");
  91             }
  92         }
  93 
  94         try {
  95             System.out.println("TRYING p.D.m PRIVATE interface-invoked as p.I.m, p.D extends p.F, p.F.m FINAL");

  96             tryAndCheckThrown(lt, bytesForDprivateSubWhat("p/F"),
  97                     "p.D extends p.F (p.F implements p.I, FINAL public m), private m",
  98                     IllegalAccessError.class, "pD_ext_pF");
  99             // We'll take either a VerifyError (pre 2013-11-30)
 100             // or an IllegalAccessError (post 2013-11-22)
 101         } catch (VerifyError ve) {
 102             System.out.println("Saw expected VerifyError " + ve);
 103         }
 104         System.out.println();
 105 
 106         System.out.println("TRYING p.D.m PRIVATE interface-invoked as p.I.m, p.D extends p.E");

 107         tryAndCheckThrown(lt, bytesForDprivateSubWhat("p/E"),
 108                 "p.D extends p.E (p.E implements p.I, public m), private m",
 109                 IllegalAccessError.class, "pD_ext_pE");
 110 
 111         System.out.println("TRYING p.D.m ABSTRACT interface-invoked as p.I.m");
 112         tryAndCheckThrown(lt, bytesForD(),
 113                 "D extends abstract C, no m",
 114                 AbstractMethodError.class, "pD_ext_pC");
 115 
 116         System.out.println("TRYING q.D.m PACKAGE interface-invoked as p.I.m");
 117         tryAndCheckThrown(lt, "q.D", bytesForDsomeAccess("q/D", 0),
 118                 "q.D implements p.I, protected m", IllegalAccessError.class,
 119                 "qD_m_pp_imp_pI");
 120 
 121         // Note jar file name is used in the plural-arg case.
 122         System.out.println("TRYING p.D.m PRIVATE interface-invoked as p.I.m");

 123         tryAndCheckThrown(lt, bytesForDsomeAccess("p/D", ACC_PRIVATE),
 124                 "p.D implements p.I, private m",
 125                 IllegalAccessError.class, "pD_m_pri_imp_pI");
 126 
 127         // Plural-arg test.
 128         System.out.println("TRYING p.D.m PRIVATE MANY ARG interface-invoked as p.I.m");

 129         tryAndCheckThrownMany(lt, bytesForDsomeAccess("p/D", ACC_PRIVATE),
 130                 "p.D implements p.I, private m", IllegalAccessError.class);
 131 
 132         if (lt.size() > 0) {
 133             System.out.flush();
 134             Thread.sleep(250); // This de-interleaves output and error in Netbeans, sigh.
 135             for (Throwable th : lt)
 136                 System.err.println(th);
 137             throw new Error("Test failed, there were " + lt.size() + " failures listed above");
 138         } else {
 139             System.out.println("ALL PASS, HOORAY!");
 140         }
 141     }
 142 
 143     /**
 144      * The bytes for D, a NOT abstract class extending abstract class C without
 145      * supplying an implementation for abstract method m. There is a default
 146      * method in the interface I, but it should lose to the abstract class.
 147      *
 148      * @return
 149      * @throws Exception
 150      */


   1 /*
   2  * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @bug 8025260 8016839 8046171
  27  * @summary Ensure that correct exceptions are thrown, not NullPointerException
  28  * @modules java.base/jdk.internal.org.objectweb.asm
  29  * @library / .
  30  *
  31  * @build p.*
  32  * @run main/othervm compiler.jsr292.methodHandleExceptions.TestAMEnotNPE
  33  * @run main/othervm -Xint compiler.jsr292.methodHandleExceptions.TestAMEnotNPE
  34  * @run main/othervm -Xcomp compiler.jsr292.methodHandleExceptions.TestAMEnotNPE
  35  */
  36 
  37 // Since this test was written the specification for interface method selection has been
  38 // revised (JEP 181 - Nestmates) so that private methods are never selected, as they never
  39 // override any inherited method. So where a private method was previously selected
  40 // and then resulted in IllegalAccessError, the private method is skipped and the invocation
  41 // will either succeed or fail based on what other implementations are found in the inheritance
  42 // hierarchy. This is explained for each test below.
  43 
  44 package compiler.jsr292.methodHandleExceptions;
  45 
  46 import p.Dok;
  47 import jdk.internal.org.objectweb.asm.ClassWriter;
  48 import jdk.internal.org.objectweb.asm.Handle;
  49 import jdk.internal.org.objectweb.asm.MethodVisitor;
  50 import jdk.internal.org.objectweb.asm.Opcodes;
  51 
  52 import java.lang.reflect.InvocationTargetException;
  53 import java.lang.reflect.Method;
  54 import java.util.ArrayList;
  55 import java.util.List;
  56 
  57 import static jdk.internal.org.objectweb.asm.Opcodes.ACC_PRIVATE;
  58 import static jdk.internal.org.objectweb.asm.Opcodes.ACC_PUBLIC;
  59 import static jdk.internal.org.objectweb.asm.Opcodes.ACC_STATIC;
  60 import static jdk.internal.org.objectweb.asm.Opcodes.ACC_SUPER;
  61 import static jdk.internal.org.objectweb.asm.Opcodes.ALOAD;
  62 import static jdk.internal.org.objectweb.asm.Opcodes.ILOAD;
  63 import static jdk.internal.org.objectweb.asm.Opcodes.INVOKESPECIAL;


  81      * found in the corresponding jar files.
  82      *
  83      * Jarfilenames look something like pD_ext_pF (p.D extends p.F)
  84      * and qD_m_pp_imp_pI (q.D with package-private m implements p.I)
  85      *
  86      */
  87     public static void main(String args[]) throws Throwable {
  88         ArrayList<Throwable> lt = new ArrayList<Throwable>();
  89 
  90         if (args.length > 0) {
  91             String a0 = args[0].toLowerCase();
  92             if (a0.length() > 0) {
  93                 writeJarFiles = ("writejarfiles").startsWith(a0);
  94                 readJarFiles = ("readjarfiles").startsWith(a0);
  95             }
  96             if (!(writeJarFiles || readJarFiles)) {
  97                 throw new Error("Command line parameter (if any) should be prefix of writeJarFiles or readJarFiles");
  98             }
  99         }
 100 

 101         System.out.println("TRYING p.D.m PRIVATE interface-invoked as p.I.m, p.D extends p.F, p.F.m FINAL");
 102         System.out.println(" - should invoke p.F.m as private p.D.m is skipped for selection");
 103         tryAndCheckThrown(lt, bytesForDprivateSubWhat("p/F"),
 104                           "p.D extends p.F (p.F implements p.I, FINAL public m), private m",
 105                           null /* should succeed */, "pD_ext_pF");





 106         System.out.println();
 107 
 108         System.out.println("TRYING p.D.m PRIVATE interface-invoked as p.I.m, p.D extends p.E");
 109         System.out.println(" - should invoke p.E.m as private p.D.m is skipped for selection");
 110         tryAndCheckThrown(lt, bytesForDprivateSubWhat("p/E"),
 111                           "p.D extends p.E (p.E implements p.I, public m), private m",
 112                           null /* should succeed */, "pD_ext_pE");
 113 
 114         System.out.println("TRYING p.D.m ABSTRACT interface-invoked as p.I.m");
 115         tryAndCheckThrown(lt, bytesForD(),
 116                           "D extends abstract C, no m",
 117                           AbstractMethodError.class, "pD_ext_pC");
 118 
 119         System.out.println("TRYING q.D.m PACKAGE interface-invoked as p.I.m");
 120         tryAndCheckThrown(lt, "q.D", bytesForDsomeAccess("q/D", 0),
 121                           "q.D implements p.I, protected m",
 122                           IllegalAccessError.class, "qD_m_pp_imp_pI");
 123 
 124         // Note jar file name is used in the plural-arg case.
 125         System.out.println("TRYING p.D.m PRIVATE interface-invoked as p.I.m");
 126         System.out.println(" - should invoke p.I.m as private p.D.m is skipped for selection");
 127         tryAndCheckThrown(lt, bytesForDsomeAccess("p/D", ACC_PRIVATE),
 128                           "p.D implements p.I, private m",
 129                           null /* should succeed */, "pD_m_pri_imp_pI");
 130 
 131         // Plural-arg test.
 132         System.out.println("TRYING p.D.m PRIVATE MANY ARG interface-invoked as p.I.m");
 133         System.out.println(" - should invoke p.I.m as private p.D.m is skipped for selection");
 134         tryAndCheckThrownMany(lt, bytesForDsomeAccess("p/D", ACC_PRIVATE),
 135                               "p.D implements p.I, private m", null /* should succeed */);
 136 
 137         if (lt.size() > 0) {
 138             System.out.flush();
 139             Thread.sleep(250); // This de-interleaves output and error in Netbeans, sigh.
 140             for (Throwable th : lt)
 141                 System.err.println(th);
 142             throw new Error("Test failed, there were " + lt.size() + " failures listed above");
 143         } else {
 144             System.out.println("ALL PASS, HOORAY!");
 145         }
 146     }
 147 
 148     /**
 149      * The bytes for D, a NOT abstract class extending abstract class C without
 150      * supplying an implementation for abstract method m. There is a default
 151      * method in the interface I, but it should lose to the abstract class.
 152      *
 153      * @return
 154      * @throws Exception
 155      */


< prev index next >