test/hotspot/jtreg/runtime/exceptionMsgs/NullPointerException/NullPointerExceptionTest.java
branchJEP-8220715-NPE_messages
changeset 57319 aa400d41ebd6
parent 57272 472db1657c6d
equal deleted inserted replaced
57318:cb67307942f3 57319:aa400d41ebd6
    25 /**
    25 /**
    26  * @test
    26  * @test
    27  * @summary Test extended NullPointerException message for class
    27  * @summary Test extended NullPointerException message for class
    28  *   files generated without debugging information. The message lists
    28  *   files generated without debugging information. The message lists
    29  *   detailed information about the entity that is null.
    29  *   detailed information about the entity that is null.
       
    30  * @modules java.base/java.lang:open
       
    31  *          java.base/jdk.internal.org.objectweb.asm
    30  * @library /test/lib
    32  * @library /test/lib
    31  * @compile NullPointerExceptionTest.java
    33  * @compile NullPointerExceptionTest.java
    32  * @run main NullPointerExceptionTest
    34  * @run main NullPointerExceptionTest
    33  */
    35  */
    34 /**
    36 /**
    35  * @test
    37  * @test
    36  * @summary Test extended NullPointerException message for
    38  * @summary Test extended NullPointerException message for
    37  *   classfiles generated with debug information. In this case the name
    39  *   classfiles generated with debug information. In this case the name
    38  *   of the variable containing the array is printed.
    40  *   of the variable containing the array is printed.
       
    41  * @modules java.base/java.lang:open
       
    42  *          java.base/jdk.internal.org.objectweb.asm
    39  * @library /test/lib
    43  * @library /test/lib
    40  * @compile -g NullPointerExceptionTest.java
    44  * @compile -g NullPointerExceptionTest.java
    41  * @run main/othervm -XX:+WizardMode -DhasDebugInfo NullPointerExceptionTest
    45  * @run main/othervm -XX:+WizardMode NullPointerExceptionTest hasDebugInfo
    42  */
    46  */
    43 
    47 
    44 import java.io.ByteArrayInputStream;
    48 import java.io.ByteArrayInputStream;
    45 import java.io.ByteArrayOutputStream;
    49 import java.io.ByteArrayOutputStream;
    46 import java.io.ObjectInputStream;
    50 import java.io.ObjectInputStream;
    47 import java.io.ObjectOutputStream;
    51 import java.io.ObjectOutputStream;
    48 import java.util.ArrayList;
    52 import java.util.ArrayList;
    49 
    53 
    50 import jdk.test.lib.Asserts;
    54 import jdk.test.lib.Asserts;
    51 
    55 
       
    56 import java.lang.reflect.*;
       
    57 import java.lang.invoke.MethodHandles.Lookup;
       
    58 import static java.lang.invoke.MethodHandles.*;
       
    59 import static java.lang.invoke.MethodHandles.Lookup.*;
       
    60 
       
    61 import jdk.internal.org.objectweb.asm.ClassWriter;
       
    62 import jdk.internal.org.objectweb.asm.MethodVisitor;
       
    63 import jdk.internal.org.objectweb.asm.Type;
       
    64 import jdk.internal.org.objectweb.asm.Label;
       
    65 import static jdk.internal.org.objectweb.asm.Opcodes.*;
       
    66 
    52 /**
    67 /**
    53  * Tests NullPointerExceptions
    68  * Tests NullPointerExceptions
    54  */
    69  */
    55 public class NullPointerExceptionTest {
    70 public class NullPointerExceptionTest {
       
    71 
    56     // Some fields used in the test.
    72     // Some fields used in the test.
    57     static Object nullStaticField;
    73     static Object nullStaticField;
    58     NullPointerExceptionTest nullInstanceField;
    74     NullPointerExceptionTest nullInstanceField;
    59     static int[][][][] staticArray;
    75     static int[][][][] staticArray;
    60     static long[][] staticLongArray = new long[1000][];
    76     static long[][] staticLongArray = new long[1000][];
    61     DoubleArrayGen dag;
    77     DoubleArrayGen dag;
    62     ArrayList<String> names = new ArrayList<>();
    78     ArrayList<String> names = new ArrayList<>();
    63     ArrayList<String> curr;
    79     ArrayList<String> curr;
    64     static boolean hasDebugInfo = true;
    80     static boolean hasDebugInfo = false;
    65 
    81 
    66     static {
    82     static {
    67         try {
       
    68             hasDebugInfo = System.getProperty("hasDebugInfo") != null;
       
    69         } catch (Throwable t) {
       
    70             throw new RuntimeException(t);
       
    71         }
       
    72 
       
    73         staticArray       = new int[1][][][];
    83         staticArray       = new int[1][][][];
    74         staticArray[0]    = new int[1][][];
    84         staticArray[0]    = new int[1][][];
    75         staticArray[0][0] = new int[1][];
    85         staticArray[0][0] = new int[1][];
    76     }
    86     }
    77 
    87 
    78     public static void checkMessage(String expression,
    88     public static void checkMessage(String expression,
    79                                     String obtainedMsg, String expectedMsg) {
    89                                     String obtainedMsg, String expectedMsg) {
    80         System.out.println();
    90         System.out.println();
    81         System.out.println(" source code: " + expression);
    91         System.out.println(" source code: " + expression);
    82         System.out.println("  thrown msg: " + obtainedMsg);
    92         System.out.println("  thrown msg: " + obtainedMsg);
    83         //System.out.println("expected msg: " + expectedMsg);
    93         if (obtainedMsg.equals(expectedMsg)) return;
    84         //Asserts.assertEquals(obtainedMsg, expectedMsg);
    94         System.out.println("expected msg: " + expectedMsg);
       
    95         Asserts.assertEquals(obtainedMsg, expectedMsg);
    85     }
    96     }
    86 
    97 
    87     public static void main(String[] args) throws Exception {
    98     public static void main(String[] args) throws Exception {
    88         NullPointerExceptionTest t = new NullPointerExceptionTest();
    99         NullPointerExceptionTest t = new NullPointerExceptionTest();
    89         t.testPointerChasing();
   100         if (args.length > 0) {
    90         t.testArrayChasing();
   101             hasDebugInfo = true;
    91         t.testMethodChasing();
   102         }
    92         t.testMixedChasing();
   103 
       
   104         // Test the message printed for the failed action.
       
   105         t.testFailedAction();
       
   106 
       
   107         // Test the method printed for the null entity.
       
   108         t.testNullEntity();
       
   109         
       
   110         // Test that no message is printed for exceptions
       
   111         // allocated explicitly.
       
   112         t.testCreation();
       
   113         
       
   114         // Test that no message is printed for exceptions
       
   115         // thrown in native methods.
       
   116         t.testNative();
       
   117 
       
   118         // Test that two calls to getMessage() return the same
       
   119         // message.
       
   120         // It is a design decision that it returns two different
       
   121         // String objects.
    93         t.testSameMessage();
   122         t.testSameMessage();
    94         t.testCreationViaNew();
   123         
    95         t.testCreationViaReflection();
   124         // Test serialization.
    96         t.testCreationViaSerialization();
   125         // It is a design decision that after serialization the
    97         t.testLoadedFromLocalVariable1();
   126         // the message is lost.
    98         t.testLoadedFromLocalVariable2();
   127         t.testSerialization();
    99         t.testLoadedFromLocalVariable3();
   128 
   100         t.testLoadedFromLocalVariable4();
   129         // Test that messages are printed for code generated 
   101         t.testLoadedFromLocalVariable5();
   130         // on-the-fly.
   102         t.testLoadedFromLocalVariable6();
   131         t.testGeneratedCode();
   103         t.testLoadedFromLocalVariable7();
   132         
   104         t.testLoadedFromMethod1();
   133 
   105         t.testLoadedFromMethod2();
   134         // Some more interesting complex messages.
   106         t.testLoadedFromMethod3();
   135         t.testComplexMessages();
   107         t.testLoadedFromMethod4();
   136     }
   108         t.testLoadedFromMethod5();
   137 
   109         t.testLoadedFromMethod6();
   138     // Helper method to cause test case.
   110         t.testLoadedFromMethod7();
   139     private double callWithTypes(String[][] dummy1, int[][][] dummy2, float dummy3, long dummy4, short dummy5, 
   111         t.testLoadedFromStaticField1();
   140                                  boolean dummy6, byte dummy7, double dummy8, char dummy9) {
   112         t.testLoadedFromStaticField2();
   141         return 0.0;
   113         t.testLoadedFromStaticField3();
   142     }
   114         t.testLoadedFromStaticField4(0, 0);
   143 
   115         t.testLoadedFromStaticField5();
   144     public void testFailedAction() {
   116         t.testLoadedFromStaticField5a();
   145         int[]     ia1 = null;
   117         t.testLoadedFromStaticField5b();
   146         float[]   fa1 = null;
   118         t.testLoadedFromStaticField6();
   147         Object[]  oa1 = null;
   119         t.testLoadedFromInstanceField1();
   148         boolean[] za1 = null;
   120         t.testLoadedFromInstanceField2();
   149         byte[]    ba1 = null;
   121         t.testLoadedFromInstanceField3();
   150         char[]    ca1 = null;
   122         t.testLoadedFromInstanceField4();
   151         short[]   sa1 = null;
   123         t.testLoadedFromInstanceField5();
   152         long[]    la1 = null;
   124         t.testLoadedFromInstanceField6();
   153         double[]  da1 = null;
   125         t.testInNative();
   154 
   126         t.testMissingLocalVariableTable();
   155         // iaload
   127         t.testNullMessages();
   156         try {
   128     }
   157             System.out.println(ia1[0]);
   129 
   158             Asserts.fail();
       
   159         } catch (NullPointerException e) {
       
   160             checkMessage("ia1[0]", e.getMessage(),
       
   161                          (hasDebugInfo ? "'ia1'" : "'<local1>'") + " is null. " +
       
   162                          "Can not load from null int array.");
       
   163         }
       
   164         // faload
       
   165         try {
       
   166             System.out.println(fa1[0]);
       
   167             Asserts.fail();
       
   168         } catch (NullPointerException e) {
       
   169             checkMessage("fa1[0]", e.getMessage(),
       
   170                          (hasDebugInfo ? "'fa1'" : "'<local2>'") + " is null. " +
       
   171                          "Can not load from null float array.");
       
   172         }
       
   173         // aaload
       
   174         try {
       
   175             System.out.println(oa1[0]);
       
   176             Asserts.fail();
       
   177         } catch (NullPointerException e) {
       
   178             checkMessage("oa1[0]", e.getMessage(),
       
   179                          (hasDebugInfo ? "'oa1'" : "'<local3>'") + " is null. " +
       
   180                          "Can not load from null object array.");
       
   181         }
       
   182         // baload (boolean)
       
   183         try {
       
   184             System.out.println(za1[0]);
       
   185             Asserts.fail();
       
   186         } catch (NullPointerException e) {
       
   187             checkMessage("za1[0]", e.getMessage(),
       
   188                          (hasDebugInfo ? "'za1'" : "'<local4>'") + " is null. " +
       
   189                          "Can not load from null byte/boolean array.");
       
   190         }
       
   191         // baload (byte)
       
   192         try {
       
   193             System.out.println(ba1[0]);
       
   194             Asserts.fail();
       
   195         } catch (NullPointerException e) {
       
   196             checkMessage("ba1[0]", e.getMessage(),
       
   197                          (hasDebugInfo ? "'ba1'" : "'<local5>'") + " is null. " +
       
   198                          "Can not load from null byte/boolean array.");
       
   199         }
       
   200         // caload
       
   201         try {
       
   202             System.out.println(ca1[0]);
       
   203             Asserts.fail();
       
   204         } catch (NullPointerException e) {
       
   205             checkMessage("ca1[0]", e.getMessage(),
       
   206                          (hasDebugInfo ? "'ca1'" : "'<local6>'") + " is null. " +
       
   207                          "Can not load from null char array.");
       
   208         }
       
   209         // saload
       
   210         try {
       
   211             System.out.println(sa1[0]);
       
   212             Asserts.fail();
       
   213         } catch (NullPointerException e) {
       
   214             checkMessage("sa1[0]", e.getMessage(),
       
   215                          (hasDebugInfo ? "'sa1'" : "'<local7>'") + " is null. " +
       
   216                          "Can not load from null short array.");
       
   217         }
       
   218         // laload
       
   219         try {
       
   220             System.out.println(la1[0]);
       
   221             Asserts.fail();
       
   222         } catch (NullPointerException e) {
       
   223             checkMessage("la1[0]", e.getMessage(),
       
   224                          (hasDebugInfo ? "'la1'" : "'<local8>'") + " is null. " +
       
   225                          "Can not load from null long array.");
       
   226         }
       
   227         // daload
       
   228         try {
       
   229             System.out.println(da1[0]);
       
   230             Asserts.fail();
       
   231         } catch (NullPointerException e) {
       
   232             checkMessage("da1[0]", e.getMessage(),
       
   233                          (hasDebugInfo ? "'da1'" : "'<local9>'") + " is null. " +
       
   234                          "Can not load from null double array.");
       
   235         }
       
   236 
       
   237         // iastore
       
   238         try {
       
   239             System.out.println(ia1[0] = 0);
       
   240             Asserts.fail();
       
   241         } catch (NullPointerException e) {
       
   242             checkMessage("ia1[0] = 0", e.getMessage(),
       
   243                          (hasDebugInfo ? "'ia1'" : "'<local1>'") + " is null. " +
       
   244                          "Can not store to null int array.");
       
   245         }
       
   246         // fastore
       
   247         try {
       
   248             System.out.println(fa1[0] = 0.7f);
       
   249             Asserts.fail();
       
   250         } catch (NullPointerException e) {
       
   251             checkMessage("fa1[0] = false", e.getMessage(),
       
   252                          (hasDebugInfo ? "'fa1'" : "'<local2>'") + " is null. " +
       
   253                          "Can not store to null float array.");
       
   254         }
       
   255         // aastore
       
   256         try {
       
   257             System.out.println(oa1[0] = null);
       
   258             Asserts.fail();
       
   259         } catch (NullPointerException e) {
       
   260             checkMessage("oa1[0] = null", e.getMessage(),
       
   261                          (hasDebugInfo ? "'oa1'" : "'<local3>'") + " is null. " +
       
   262                          "Can not store to null object array.");
       
   263         }
       
   264         // bastore (boolean)
       
   265         try {
       
   266             System.out.println(za1[0] = false);
       
   267             Asserts.fail();
       
   268         } catch (NullPointerException e) {
       
   269             checkMessage("za1[0] = false", e.getMessage(),
       
   270                          (hasDebugInfo ? "'za1'" : "'<local4>'") + " is null. " +
       
   271                          "Can not store to null byte/boolean array.");
       
   272         }
       
   273         // bastore (byte)
       
   274         try {
       
   275             System.out.println(ba1[0] = 0);
       
   276             Asserts.fail();
       
   277         } catch (NullPointerException e) {
       
   278             checkMessage("ba1[0] = 0", e.getMessage(),
       
   279                          (hasDebugInfo ? "'ba1'" : "'<local5>'") + " is null. " +
       
   280                          "Can not store to null byte/boolean array.");
       
   281         }
       
   282         // castore
       
   283         try {
       
   284             System.out.println(ca1[0] = 0);
       
   285             Asserts.fail();
       
   286         } catch (NullPointerException e) {
       
   287             checkMessage("ca1[0] = 0", e.getMessage(),
       
   288                          (hasDebugInfo ? "'ca1'" : "'<local6>'") + " is null. " +
       
   289                          "Can not store to null char array.");
       
   290         }
       
   291         // sastore
       
   292         try {
       
   293             System.out.println(sa1[0] = 0);
       
   294             Asserts.fail();
       
   295         } catch (NullPointerException e) {
       
   296             checkMessage("sa1[0] = 0", e.getMessage(),
       
   297                          (hasDebugInfo ? "'sa1'" : "'<local7>'") + " is null. " +
       
   298                          "Can not store to null short array.");
       
   299         }
       
   300         // lastore
       
   301         try {
       
   302             System.out.println(la1[0] = 0);
       
   303             Asserts.fail();
       
   304         } catch (NullPointerException e) {
       
   305             checkMessage("la1[0] = 0", e.getMessage(),
       
   306                          (hasDebugInfo ? "'la1'" : "'<local8>'") + " is null. " +
       
   307                          "Can not store to null long array.");
       
   308         }
       
   309         // dastore
       
   310         try {
       
   311             System.out.println(da1[0] = 0);
       
   312             Asserts.fail();
       
   313         } catch (NullPointerException e) {
       
   314             checkMessage("da1[0] = 0", e.getMessage(),
       
   315                          (hasDebugInfo ? "'da1'" : "'<local9>'") + " is null. " +
       
   316                          "Can not store to null double array.");
       
   317         }
       
   318 
       
   319         // arraylength
       
   320         try {
       
   321             System.out.println(za1.length);
       
   322             Asserts.fail();
       
   323         } catch (NullPointerException e) {
       
   324             checkMessage("za1.length", e.getMessage(),
       
   325                          (hasDebugInfo ? "'za1'" : "'<local4>'") + " is null. " +
       
   326                          "Can not read the array length.");
       
   327         }
       
   328         // athrow
       
   329         try {
       
   330             throw null;
       
   331         } catch (NullPointerException e) {
       
   332             checkMessage("throw null", e.getMessage(),
       
   333                          "'null' is null. " +
       
   334                          "Can not throw a null exception object.");
       
   335         }
       
   336         // monitorenter
       
   337         try {
       
   338             synchronized (nullInstanceField) {
       
   339                 // desired
       
   340             }
       
   341         } catch (NullPointerException e) {
       
   342             checkMessage("synchronized (nullInstanceField)", e.getMessage(),
       
   343                          "'this.nullInstanceField' is null. " +
       
   344                          "Can not enter a null monitor.");
       
   345         }
       
   346         // monitorexit
       
   347         // No test available
       
   348 
       
   349         // getfield
       
   350         try {
       
   351             System.out.println(nullInstanceField.nullInstanceField);
       
   352             Asserts.fail();
       
   353         } catch (NullPointerException e) {
       
   354             checkMessage("nullInstanceField.nullInstanceField", e.getMessage(),
       
   355                          "'this.nullInstanceField' is null. " +
       
   356                          "Can not read field 'nullInstanceField'.");
       
   357         }
       
   358         // putfield
       
   359         try {
       
   360             System.out.println(nullInstanceField.nullInstanceField = null);
       
   361             Asserts.fail();
       
   362         } catch (NullPointerException e) {
       
   363             checkMessage("nullInstanceField.nullInstanceField = null", e.getMessage(),
       
   364                          "'this.nullInstanceField' is null. " +
       
   365                          "Can not write field 'nullInstanceField'.");
       
   366         }
       
   367         // invoke
       
   368         try {
       
   369             nullInstanceField.toString();
       
   370             Asserts.fail();
       
   371         } catch (NullPointerException e) {
       
   372             checkMessage("nullInstanceField.toString()", e.getMessage(),
       
   373                          "'this.nullInstanceField' is null. " +
       
   374                          "Can not invoke method 'java.lang.String java.lang.Object.toString()'.");
       
   375         }
       
   376         // Test parameter and return types
       
   377         try {
       
   378             Asserts.assertTrue(nullInstanceField.callWithTypes(null, null, 0.0f, 0L, (short)0, false, (byte)0, 0.0, 'x') == 0.0);
       
   379             Asserts.fail();
       
   380         } catch (NullPointerException e) {
       
   381             checkMessage("nullInstanceField.callWithTypes(null, null, 0.0f, 0L, (short)0, false, (byte)0, 0.0, 'x')", e.getMessage(),
       
   382                          "'this.nullInstanceField' is null. " +
       
   383                          "Can not invoke method 'double NullPointerExceptionTest.callWithTypes(java.lang.String[][], int[][][], float, long, short, boolean, byte, double, char)'.");
       
   384         }
       
   385     }
       
   386 
       
   387     static void test_iload() {
       
   388         int i0 = 0;
       
   389         int i1 = 1;
       
   390         int i2 = 2;
       
   391         int i3 = 3;
       
   392         int i4 = 4;
       
   393         int i5 = 5;
       
   394         
       
   395         int[][] a = new int[6][];
       
   396 
       
   397         // iload_0
       
   398         try {
       
   399             a[i0][0] = 77;
       
   400             Asserts.fail();
       
   401         } catch (NullPointerException e) {
       
   402             checkMessage("a[i0][0]", e.getMessage(),
       
   403                          (hasDebugInfo ? "'a[i0]'" : "'<local6>[<local0>]'") + " is null. " +
       
   404                          "Can not store to null int array.");
       
   405         }
       
   406         // iload_1
       
   407         try {
       
   408             a[i1][0] = 77;
       
   409             Asserts.fail();
       
   410         } catch (NullPointerException e) {
       
   411             checkMessage("a[i1][0]", e.getMessage(),
       
   412                          (hasDebugInfo ? "'a[i1]'" : "'<local6>[<local1>]'") + " is null. " +
       
   413                          "Can not store to null int array.");
       
   414         }
       
   415         // iload_2
       
   416         try {
       
   417             a[i2][0] = 77;
       
   418             Asserts.fail();
       
   419         } catch (NullPointerException e) {
       
   420             checkMessage("a[i2][0]", e.getMessage(),
       
   421                          (hasDebugInfo ? "'a[i2]'" : "'<local6>[<local2>]'") + " is null. " +
       
   422                          "Can not store to null int array.");
       
   423         }
       
   424         // iload_3
       
   425         try {
       
   426             a[i3][0] = 77;
       
   427             Asserts.fail();
       
   428         } catch (NullPointerException e) {
       
   429             checkMessage("a[i3][0]", e.getMessage(),
       
   430                          (hasDebugInfo ? "'a[i3]'" : "'<local6>[<local3>]'") + " is null. " +
       
   431                          "Can not store to null int array.");
       
   432         }
       
   433         // iload
       
   434         try {
       
   435             a[i5][0] = 77;
       
   436             Asserts.fail();
       
   437         } catch (NullPointerException e) {
       
   438             checkMessage("a[i5][0]", e.getMessage(),
       
   439                          (hasDebugInfo ? "'a[i5]'" : "'<local6>[<local5>]'") + " is null. " +
       
   440                          "Can not store to null int array.");
       
   441         }
       
   442     }
       
   443 
       
   444     // Other datatyes than int are not needed.
       
   445     // If we implement l2d and similar bytecodes, we can print
       
   446     // long expressions as array indexes. Then these here could
       
   447     // be used.
       
   448     static void test_lload() {
       
   449         long l0 = 0L;
       
   450         long l1 = 1L;
       
   451         long l2 = 2L;
       
   452         long l3 = 3L;
       
   453         long l4 = 4L;
       
   454         long l5 = 5L;
       
   455         
       
   456         int[][] a = new int[6][];
       
   457 
       
   458         // lload_0
       
   459         try {
       
   460             a[(int)l0][0] = 77;
       
   461             Asserts.fail();
       
   462         } catch (NullPointerException e) {
       
   463             checkMessage("a[(int)l0][0]", e.getMessage(),
       
   464                          (hasDebugInfo ? "'a[...]'" : "'<local12>[...]'") + " is null. " +
       
   465                          "Can not store to null int array.");
       
   466         }
       
   467         // lload_1
       
   468         try {
       
   469             a[(int)l1][0] = 77;
       
   470             Asserts.fail();
       
   471         } catch (NullPointerException e) {
       
   472             checkMessage("a[(int)l1][0]", e.getMessage(),
       
   473                          (hasDebugInfo ? "'a[...]'" : "'<local12>[...]'") + " is null. " +
       
   474                          "Can not store to null int array.");
       
   475         }
       
   476         // lload_2
       
   477         try {
       
   478             a[(int)l2][0] = 77;
       
   479             Asserts.fail();
       
   480         } catch (NullPointerException e) {
       
   481             checkMessage("a[(int)l2][0]", e.getMessage(),
       
   482                          (hasDebugInfo ? "'a[...]'" : "'<local12>[...]'") + " is null. " +
       
   483                          "Can not store to null int array.");
       
   484         }
       
   485         // lload_3
       
   486         try {
       
   487             a[(int)l3][0] = 77;
       
   488             Asserts.fail();
       
   489         } catch (NullPointerException e) {
       
   490             checkMessage("a[(int)l3][0]", e.getMessage(),
       
   491                          (hasDebugInfo ? "'a[...]'" : "'<local12>[...]'") + " is null. " +
       
   492                          "Can not store to null int array.");
       
   493         }
       
   494         // lload
       
   495         try {
       
   496             a[(int)l5][0] = 77;
       
   497             Asserts.fail();
       
   498         } catch (NullPointerException e) {
       
   499             checkMessage("a[(int)l5][0]", e.getMessage(),
       
   500                          (hasDebugInfo ? "'a[...]'" : "'<local12>[...]'") + " is null. " +
       
   501                          "Can not store to null int array.");
       
   502         }        
       
   503     }
       
   504 
       
   505     static void test_fload() {
       
   506         float f0 = 0.0f;
       
   507         float f1 = 1.0f;
       
   508         float f2 = 2.0f;
       
   509         float f3 = 3.0f;
       
   510         float f4 = 4.0f;
       
   511         float f5 = 5.0f;
       
   512         
       
   513         int[][] a = new int[6][];
       
   514 
       
   515         // fload_0
       
   516         try {
       
   517             a[(int)f0][0] = 77;
       
   518             Asserts.fail();
       
   519         } catch (NullPointerException e) {
       
   520             checkMessage("a[(int)f0][0]", e.getMessage(),
       
   521                          (hasDebugInfo ? "'a[...]'" : "'<local6>[...]'") + " is null. " +
       
   522                          "Can not store to null int array.");
       
   523         }
       
   524         // fload_1
       
   525         try {
       
   526             a[(int)f1][0] = 77;
       
   527             Asserts.fail();
       
   528         } catch (NullPointerException e) {
       
   529             checkMessage("a[(int)f1][0]", e.getMessage(),
       
   530                          (hasDebugInfo ? "'a[...]'" : "'<local6>[...]'") + " is null. " +
       
   531                          "Can not store to null int array.");
       
   532         }
       
   533         // fload_2
       
   534         try {
       
   535             a[(int)f2][0] = 77;
       
   536             Asserts.fail();
       
   537         } catch (NullPointerException e) {
       
   538             checkMessage("a[(int)f2][0]", e.getMessage(),
       
   539                          (hasDebugInfo ? "'a[...]'" : "'<local6>[...]'") + " is null. " +
       
   540                          "Can not store to null int array.");
       
   541         }
       
   542         // fload_3
       
   543         try {
       
   544             a[(int)f3][0] = 77;
       
   545             Asserts.fail();
       
   546         } catch (NullPointerException e) {
       
   547             checkMessage("a[(int)f3][0]", e.getMessage(),
       
   548                          (hasDebugInfo ? "'a[...]'" : "'<local6>[...]'") + " is null. " +
       
   549                          "Can not store to null int array.");
       
   550         }
       
   551         // fload
       
   552         try {
       
   553             a[(int)f5][0] = 77;
       
   554             Asserts.fail();
       
   555         } catch (NullPointerException e) {
       
   556             checkMessage("a[(int)f5][0]", e.getMessage(),
       
   557                          (hasDebugInfo ? "'a[...]'" : "'<local6>[...]'") + " is null. " +
       
   558                          "Can not store to null int array.");
       
   559         }        
       
   560     }
       
   561 
       
   562     static void test_aload() {
       
   563         F f0 = null;
       
   564         F f1 = null;
       
   565         F f2 = null;
       
   566         F f3 = null;
       
   567         F f4 = null;
       
   568         F f5 = null;
       
   569 
       
   570         // aload_0
       
   571         try {
       
   572             f0.i = 33;
       
   573             Asserts.fail();
       
   574         } catch (NullPointerException e) {
       
   575             checkMessage("f0.i", e.getMessage(),
       
   576                          (hasDebugInfo ? "'f0'" : "'<local0>'") + " is null. " +
       
   577                          "Can not write field 'i'.");
       
   578         }
       
   579         // aload_1
       
   580         try {
       
   581             f1.i = 33;
       
   582             Asserts.fail();
       
   583         } catch (NullPointerException e) {
       
   584             checkMessage("f1.i", e.getMessage(),
       
   585                          (hasDebugInfo ? "'f1'" : "'<local1>'") + " is null. " +
       
   586                          "Can not write field 'i'.");
       
   587         }
       
   588         // aload_2
       
   589         try {
       
   590             f2.i = 33;
       
   591             Asserts.fail();
       
   592         } catch (NullPointerException e) {
       
   593             checkMessage("f2.i", e.getMessage(),
       
   594                          (hasDebugInfo ? "'f2'" : "'<local2>'") + " is null. " +
       
   595                          "Can not write field 'i'.");
       
   596         }
       
   597         // aload_3
       
   598         try {
       
   599             f3.i = 33;
       
   600             Asserts.fail();
       
   601         } catch (NullPointerException e) {
       
   602             checkMessage("f3.i", e.getMessage(),
       
   603                          (hasDebugInfo ? "'f3'" : "'<local3>'") + " is null. " +
       
   604                          "Can not write field 'i'.");
       
   605         }
       
   606         // aload
       
   607         try {
       
   608             f5.i = 33;
       
   609             Asserts.fail();
       
   610         } catch (NullPointerException e) {
       
   611             checkMessage("f5.i", e.getMessage(),
       
   612                          (hasDebugInfo ? "'f5'" : "'<local5>'") + " is null. " +
       
   613                          "Can not write field 'i'.");
       
   614         } 
       
   615     }
       
   616 
       
   617     // Helper class for test cases.
   130     class A {
   618     class A {
   131         public B to_b;
   619         public B to_b;
   132         public B getB() { return to_b; }
   620         public B getB() { return to_b; }
   133     }
   621     }
   134 
   622 
       
   623     // Helper class for test cases.
   135     class B {
   624     class B {
   136         public C to_c;
   625         public C to_c;
   137         public B to_b;
   626         public B to_b;
   138         public C getC() { return to_c; }
   627         public C getC() { return to_c; }
   139         public B getBfromB() { return to_b; }
   628         public B getBfromB() { return to_b; }
   140     }
   629     }
   141 
   630 
       
   631     // Helper class for test cases.
   142     class C {
   632     class C {
   143         public D to_d;
   633         public D to_d;
   144         public D getD() { return to_d; }
   634         public D getD() { return to_d; }
   145     }
   635     }
   146 
   636 
       
   637     // Helper class for test cases.
   147     class D {
   638     class D {
   148         public int num;
   639         public int num;
   149         public int[][] ar;
   640         public int[][] ar;
   150     }
   641     }
   151 
   642 
       
   643 
       
   644     public void testArrayChasing() {
       
   645         int[][][][][][] a = null;
       
   646         try {
       
   647             a[0][0][0][0][0][0] = 99;
       
   648             Asserts.fail();
       
   649         } catch (NullPointerException e) {
       
   650             checkMessage("int[0][0][0][0][0] = 99 // a is null", e.getMessage(),
       
   651                          (hasDebugInfo ? "'a'" : "'<local1>'") + " is null. " +
       
   652                          "Can not load from null object array.");
       
   653         }
       
   654         a = new int[1][][][][][];
       
   655         try {
       
   656             a[0][0][0][0][0][0] = 99;
       
   657             Asserts.fail();
       
   658         } catch (NullPointerException e) {
       
   659             checkMessage("int[0][0][0][0][0] = 99 // a[0] is null", e.getMessage(),
       
   660                          (hasDebugInfo ? "'a[0]'" : "'<local1>[0]'") + " is null. " +
       
   661                          "Can not load from null object array.");
       
   662         }
       
   663         a[0] = new int[1][][][][];
       
   664         try {
       
   665             a[0][0][0][0][0][0] = 99;
       
   666             Asserts.fail();
       
   667         } catch (NullPointerException e) {
       
   668             checkMessage("int[0][0][0][0][0] = 99 // a[0][0] is null", e.getMessage(),
       
   669                          (hasDebugInfo ? "'a[0][0]'" : "'<local1>[0][0]'") + " is null. " +
       
   670                          "Can not load from null object array.");
       
   671         }
       
   672         a[0][0] = new int[1][][][];
       
   673         try {
       
   674             a[0][0][0][0][0][0] = 99;
       
   675             Asserts.fail();
       
   676         } catch (NullPointerException e) {
       
   677             checkMessage("int[0][0][0][0][0] = 99 // a[0][0][0] is null", e.getMessage(),
       
   678                          (hasDebugInfo ? "'a[0][0][0]'" : "'<local1>[0][0][0]'") + " is null. " +
       
   679                          "Can not load from null object array.");
       
   680         }
       
   681         a[0][0][0] = new int[1][][];
       
   682         try {
       
   683             a[0][0][0][0][0][0] = 99;
       
   684             Asserts.fail();
       
   685         } catch (NullPointerException e) {
       
   686             checkMessage("int[0][0][0][0][0] = 99 // a[0][0][0][0] is null", e.getMessage(),
       
   687                          (hasDebugInfo ? "'a[0][0][0][0]'" : "'<local1>[0][0][0][0]'") + " is null. " +
       
   688                          "Can not load from null object array.");
       
   689         }
       
   690         a[0][0][0][0] = new int[1][];
       
   691         // Reaching max recursion depth. Prints <array>.
       
   692         try {
       
   693             a[0][0][0][0][0][0] = 99;
       
   694             Asserts.fail();
       
   695         } catch (NullPointerException e) {
       
   696             checkMessage("int[0][0][0][0][0] = 99 // a[0][0][0][0][0] is null", e.getMessage(),
       
   697                          "'<array>[0][0][0][0][0]' is null. " +
       
   698                          "Can not store to null int array.");
       
   699         }
       
   700         a[0][0][0][0][0] = new int[1];
       
   701         try {
       
   702             a[0][0][0][0][0][0] = 99;
       
   703         } catch (NullPointerException e) {
       
   704             Asserts.fail();
       
   705         }
       
   706     }
       
   707 
   152     public void testPointerChasing() {
   708     public void testPointerChasing() {
   153         A a = null;
   709         A a = null;
   154         try {
   710         try {
   155             a.to_b.to_c.to_d.num = 99;
   711             a.to_b.to_c.to_d.num = 99;
   156             Asserts.fail();
   712             Asserts.fail();
   157         } catch (NullPointerException e) {
   713         } catch (NullPointerException e) {
   158             checkMessage("a.to_b.to_c.to_d.num = 99 // a is null", e.getMessage(),
   714             checkMessage("a.to_b.to_c.to_d.num = 99 // a is null", e.getMessage(),
   159                          "while trying to read the field 'to_b' of a null object loaded from " +
   715                          (hasDebugInfo ? "'a'" : "'<local1>'") + " is null. " +
   160                          (hasDebugInfo ? "local variable 'a'" : "a local variable at slot 1"));
   716                          "Can not read field 'to_b'.");
   161         }
   717         }
   162         a = new A();
   718         a = new A();
   163         try {
   719         try {
   164             a.to_b.to_c.to_d.num = 99;
   720             a.to_b.to_c.to_d.num = 99;
   165             Asserts.fail();
   721             Asserts.fail();
   166         } catch (NullPointerException e) {
   722         } catch (NullPointerException e) {
   167             checkMessage("a.to_b.to_c.to_d.num = 99 // a.to_b is null", e.getMessage(),
   723             checkMessage("a.to_b.to_c.to_d.num = 99 // a.to_b is null", e.getMessage(),
   168                          "while trying to read the field 'to_c' of a null object loaded from field 'NullPointerExceptionTest$A.to_b' of an object loaded from " +
   724                          (hasDebugInfo ? "'a.to_b'" : "'<local1>.to_b'") + " is null. " +
   169                          (hasDebugInfo ? "local variable 'a'" : "a local variable at slot 1"));
   725                          "Can not read field 'to_c'.");
   170         }
   726         }
   171         a.to_b = new B();
   727         a.to_b = new B();
   172         try {
   728         try {
   173             a.to_b.to_c.to_d.num = 99;
   729             a.to_b.to_c.to_d.num = 99;
   174             Asserts.fail();
   730             Asserts.fail();
   175         } catch (NullPointerException e) {
   731         } catch (NullPointerException e) {
   176             checkMessage("a.to_b.to_c.to_d.num = 99 // a.to_b.to_c is null", e.getMessage(),
   732             checkMessage("a.to_b.to_c.to_d.num = 99 // a.to_b.to_c is null", e.getMessage(),
   177                          "while trying to read the field 'to_d' of a null object loaded from field 'NullPointerExceptionTest$B.to_c' of an object loaded from field 'NullPointerExceptionTest$A.to_b' of an object");
   733                          (hasDebugInfo ? "'a.to_b.to_c'" : "'<local1>.to_b.to_c'") + " is null. " +
       
   734                          "Can not read field 'to_d'.");
   178         }
   735         }
   179         a.to_b.to_c = new C();
   736         a.to_b.to_c = new C();
   180         try {
   737         try {
   181             a.to_b.to_c.to_d.num = 99;
   738             a.to_b.to_c.to_d.num = 99;
   182             Asserts.fail();
   739             Asserts.fail();
   183         } catch (NullPointerException e) {
   740         } catch (NullPointerException e) {
   184             checkMessage("a.to_b.to_c.to_d.num = 99 // a.to_b.to_c.to_d is null", e.getMessage(),
   741             checkMessage("a.to_b.to_c.to_d.num = 99 // a.to_b.to_c.to_d is null", e.getMessage(),
   185                          "while trying to write the field 'NullPointerExceptionTest$D.num' of a null object loaded from field 'NullPointerExceptionTest$C.to_d' of an object loaded from field 'NullPointerExceptionTest$B.to_c' of an object");
   742                          (hasDebugInfo ? "'a.to_b.to_c.to_d'" : "'<local1>.to_b.to_c.to_d'") + " is null. " +
   186         }
   743                          "Can not write field 'num'.");
   187     }
       
   188 
       
   189     public void testArrayChasing() {
       
   190         int[][][][][] a = null;
       
   191         try {
       
   192             a[0][0][0][0][0] = 99;
       
   193             Asserts.fail();
       
   194         } catch (NullPointerException e) {
       
   195             checkMessage("int[0][0][0][0][0] = 99 // a is null", e.getMessage(),
       
   196                          "while trying to load from a null object array loaded from " +
       
   197                          (hasDebugInfo ? "local variable 'a'" : "a local variable at slot 1"));
       
   198         }
       
   199         a = new int[1][][][][];
       
   200         try {
       
   201             a[0][0][0][0][0] = 99;
       
   202             Asserts.fail();
       
   203         } catch (NullPointerException e) {
       
   204             checkMessage("int[0][0][0][0][0] = 99 // a[0] is null", e.getMessage(),
       
   205                          "while trying to load from a null object array loaded from an array (which itself was loaded from " +
       
   206                          (hasDebugInfo ? "local variable 'a'" : "a local variable at slot 1") +
       
   207                          ") with an index loaded from a constant");
       
   208         }
       
   209         a[0] = new int[1][][][];
       
   210         try {
       
   211             a[0][0][0][0][0] = 99;
       
   212             Asserts.fail();
       
   213         } catch (NullPointerException e) {
       
   214             checkMessage("int[0][0][0][0][0] = 99 // a[0][0] is null", e.getMessage(),
       
   215                          "while trying to load from a null object array loaded from an array (which itself was loaded from an array) with an index loaded from a constant");
       
   216         }
       
   217         a[0][0] = new int[1][][];
       
   218         try {
       
   219             a[0][0][0][0][0] = 99;
       
   220             Asserts.fail();
       
   221         } catch (NullPointerException e) {
       
   222             checkMessage("int[0][0][0][0][0] = 99 // a[0][0][0] is null", e.getMessage(),
       
   223                          "while trying to load from a null object array loaded from an array (which itself was loaded from an array) with an index loaded from a constant");
       
   224         }
       
   225         a[0][0][0] = new int[1][];
       
   226         try {
       
   227             a[0][0][0][0][0] = 99;
       
   228             Asserts.fail();
       
   229         } catch (NullPointerException e) {
       
   230             checkMessage("int[0][0][0][0][0] = 99 // a[0][0][0][0] is null", e.getMessage(),
       
   231                          "while trying to store to a null int array loaded from an array (which itself was loaded from an array) with an index loaded from a constant");
       
   232         }
       
   233         a[0][0][0][0] = new int[1];
       
   234         try {
       
   235             a[0][0][0][0][0] = 99;
       
   236         } catch (NullPointerException e) {
       
   237             Asserts.fail();
       
   238         }
   744         }
   239     }
   745     }
   240 
   746 
   241     public void testMethodChasing() {
   747     public void testMethodChasing() {
   242         A a = null;
   748         A a = null;
   243         try {
   749         try {
   244             a.getB().getBfromB().getC().getD().num = 99;
   750             a.getB().getBfromB().getC().getD().num = 99;
   245             Asserts.fail();
   751             Asserts.fail();
   246         } catch (NullPointerException e) {
   752         } catch (NullPointerException e) {
   247             checkMessage("a.getB().getBfromB().getC().getD().num = 99 // a is null", e.getMessage(),
   753             checkMessage("a.getB().getBfromB().getC().getD().num = 99 // a is null", e.getMessage(),
   248                          "while trying to invoke the method 'NullPointerExceptionTest$A.getB()LNullPointerExceptionTest$B;' on a null reference loaded from " +
   754                          (hasDebugInfo ? "'a" : "'<local1>") + "' is null. " +
   249                          (hasDebugInfo ? "local variable 'a'" : "a local variable at slot 1"));
   755                          "Can not invoke method 'NullPointerExceptionTest$B NullPointerExceptionTest$A.getB()'.");
   250         }
   756         }
   251         a = new A();
   757         a = new A();
   252         try {
   758         try {
   253             a.getB().getBfromB().getC().getD().num = 99;
   759             a.getB().getBfromB().getC().getD().num = 99;
   254             Asserts.fail();
   760             Asserts.fail();
   255         } catch (NullPointerException e) {
   761         } catch (NullPointerException e) {
   256             checkMessage("a.getB().getBfromB().getC().getD().num = 99 // a.getB() is null", e.getMessage(),
   762             checkMessage("a.getB().getBfromB().getC().getD().num = 99 // a.getB() is null", e.getMessage(),
   257                          "while trying to invoke the method 'NullPointerExceptionTest$B.getBfromB()LNullPointerExceptionTest$B;' on a null reference returned from 'NullPointerExceptionTest$A.getB()LNullPointerExceptionTest$B;'");
   763                          "The return value of 'NullPointerExceptionTest$B NullPointerExceptionTest$A.getB()' is null. " +
       
   764                          "Can not invoke method 'NullPointerExceptionTest$B NullPointerExceptionTest$B.getBfromB()'.");
   258         }
   765         }
   259         a.to_b = new B();
   766         a.to_b = new B();
   260         try {
   767         try {
   261             a.getB().getBfromB().getC().getD().num = 99;
   768             a.getB().getBfromB().getC().getD().num = 99;
   262             Asserts.fail();
   769             Asserts.fail();
   263         } catch (NullPointerException e) {
   770         } catch (NullPointerException e) {
   264             checkMessage("a.getB().getBfromB().getC().getD().num = 99 // a.getB().getBfromB() is null", e.getMessage(),
   771             checkMessage("a.getB().getBfromB().getC().getD().num = 99 // a.getB().getBfromB() is null", e.getMessage(),
   265                          "while trying to invoke the method 'NullPointerExceptionTest$B.getC()LNullPointerExceptionTest$C;' on a null reference returned from 'NullPointerExceptionTest$B.getBfromB()LNullPointerExceptionTest$B;'");
   772                          "The return value of 'NullPointerExceptionTest$B NullPointerExceptionTest$B.getBfromB()' is null. " +
       
   773                          "Can not invoke method 'NullPointerExceptionTest$C NullPointerExceptionTest$B.getC()'.");
   266         }
   774         }
   267         a.to_b.to_b = new B();
   775         a.to_b.to_b = new B();
   268         try {
   776         try {
   269             a.getB().getBfromB().getC().getD().num = 99;
   777             a.getB().getBfromB().getC().getD().num = 99;
   270             Asserts.fail();
   778             Asserts.fail();
   271         } catch (NullPointerException e) {
   779         } catch (NullPointerException e) {
   272             checkMessage("a.getB().getBfromB().getC().getD().num = 99 // a.getB().getBfromB().getC() is null", e.getMessage(),
   780             checkMessage("a.getB().getBfromB().getC().getD().num = 99 // a.getB().getBfromB().getC() is null", e.getMessage(),
   273                          "while trying to invoke the method 'NullPointerExceptionTest$C.getD()LNullPointerExceptionTest$D;' on a null reference returned from 'NullPointerExceptionTest$B.getC()LNullPointerExceptionTest$C;'");
   781                          "The return value of 'NullPointerExceptionTest$C NullPointerExceptionTest$B.getC()' is null. " +
       
   782                          "Can not invoke method 'NullPointerExceptionTest$D NullPointerExceptionTest$C.getD()'.");
   274         }
   783         }
   275         a.to_b.to_b.to_c = new C();
   784         a.to_b.to_b.to_c = new C();
   276         try {
   785         try {
   277             a.getB().getBfromB().getC().getD().num = 99;
   786             a.getB().getBfromB().getC().getD().num = 99;
   278             Asserts.fail();
   787             Asserts.fail();
   279         } catch (NullPointerException e) {
   788         } catch (NullPointerException e) {
   280             checkMessage("a.getB().getBfromB().getC().getD().num = 99 // a.getB().getBfromB().getC().getD() is null", e.getMessage(),
   789             checkMessage("a.getB().getBfromB().getC().getD().num = 99 // a.getB().getBfromB().getC().getD() is null", e.getMessage(),
   281                          "while trying to write the field 'NullPointerExceptionTest$D.num' of a null object returned from 'NullPointerExceptionTest$C.getD()LNullPointerExceptionTest$D;'");
   790                          "The return value of 'NullPointerExceptionTest$D NullPointerExceptionTest$C.getD()' is null. " +
       
   791                          "Can not write field 'num'.");
   282         }
   792         }
   283     }
   793     }
   284 
   794 
   285     public void testMixedChasing() {
   795     public void testMixedChasing() {
   286         A a = null;
   796         A a = null;
   287         try {
   797         try {
   288             a.getB().getBfromB().to_c.to_d.ar[0][0] = 99;
   798             a.getB().getBfromB().to_c.to_d.ar[0][0] = 99;
   289             Asserts.fail();
   799             Asserts.fail();
   290         } catch (NullPointerException e) {
   800         } catch (NullPointerException e) {
   291             checkMessage("a.getB().getBfromB().to_c.to_d.ar[0][0] = 99; // a is null", e.getMessage(),
   801             checkMessage("a.getB().getBfromB().to_c.to_d.ar[0][0] = 99; // a is null", e.getMessage(),
   292                          "while trying to invoke the method 'NullPointerExceptionTest$A.getB()LNullPointerExceptionTest$B;' on a null reference loaded from " +
   802                          (hasDebugInfo ? "'a'" : "'<local1>'") + " is null. " +
   293                          (hasDebugInfo ? "local variable 'a'" : "a local variable at slot 1"));
   803                          "Can not invoke method 'NullPointerExceptionTest$B NullPointerExceptionTest$A.getB()'.");
   294         }
   804         }
   295         a = new A();
   805         a = new A();
   296         try {
   806         try {
   297             a.getB().getBfromB().to_c.to_d.ar[0][0] = 99;
   807             a.getB().getBfromB().to_c.to_d.ar[0][0] = 99;
   298             Asserts.fail();
   808             Asserts.fail();
   299         } catch (NullPointerException e) {
   809         } catch (NullPointerException e) {
   300             checkMessage("a.getB().getBfromB().to_c.to_d.ar[0][0] = 99; // a.getB() is null", e.getMessage(),
   810             checkMessage("a.getB().getBfromB().to_c.to_d.ar[0][0] = 99; // a.getB() is null", e.getMessage(),
   301                          "while trying to invoke the method 'NullPointerExceptionTest$B.getBfromB()LNullPointerExceptionTest$B;' on a null reference returned from 'NullPointerExceptionTest$A.getB()LNullPointerExceptionTest$B;'");
   811                          "The return value of 'NullPointerExceptionTest$B NullPointerExceptionTest$A.getB()' is null. " +
       
   812                          "Can not invoke method 'NullPointerExceptionTest$B NullPointerExceptionTest$B.getBfromB()'.");
   302         }
   813         }
   303         a.to_b = new B();
   814         a.to_b = new B();
   304         try {
   815         try {
   305             a.getB().getBfromB().to_c.to_d.ar[0][0] = 99;
   816             a.getB().getBfromB().to_c.to_d.ar[0][0] = 99;
   306             Asserts.fail();
   817             Asserts.fail();
   307         } catch (NullPointerException e) {
   818         } catch (NullPointerException e) {
   308             checkMessage("a.getB().getBfromB().to_c.to_d.ar[0][0] = 99; // a.getB().getBfromB() is null", e.getMessage(),
   819             checkMessage("a.getB().getBfromB().to_c.to_d.ar[0][0] = 99; // a.getB().getBfromB() is null", e.getMessage(),
   309                          "while trying to read the field 'to_c' of a null object returned from 'NullPointerExceptionTest$B.getBfromB()LNullPointerExceptionTest$B;'");
   820                          "The return value of 'NullPointerExceptionTest$B NullPointerExceptionTest$B.getBfromB()' is null. " +
       
   821                          "Can not read field 'to_c'.");
   310         }
   822         }
   311         a.to_b.to_b = new B();
   823         a.to_b.to_b = new B();
   312         try {
   824         try {
   313             a.getB().getBfromB().to_c.to_d.ar[0][0] = 99;
   825             a.getB().getBfromB().to_c.to_d.ar[0][0] = 99;
   314             Asserts.fail();
   826             Asserts.fail();
   315         } catch (NullPointerException e) {
   827         } catch (NullPointerException e) {
   316             checkMessage("a.getB().getBfromB().to_c.to_d.ar[0][0] = 99; // a.getB().getBfromB().to_c is null", e.getMessage(),
   828             checkMessage("a.getB().getBfromB().to_c.to_d.ar[0][0] = 99; // a.getB().getBfromB().to_c is null", e.getMessage(),
   317                          "while trying to read the field 'to_d' of a null object loaded from field 'NullPointerExceptionTest$B.to_c' of an object returned from 'NullPointerExceptionTest$B.getBfromB()LNullPointerExceptionTest$B;'");
   829                          "'NullPointerExceptionTest$B NullPointerExceptionTest$B.getBfromB().to_c' is null. " +
       
   830                          "Can not read field 'to_d'.");
   318         }
   831         }
   319         a.to_b.to_b.to_c = new C();
   832         a.to_b.to_b.to_c = new C();
   320         try {
   833         try {
   321             a.getB().getBfromB().to_c.to_d.ar[0][0] = 99;
   834             a.getB().getBfromB().to_c.to_d.ar[0][0] = 99;
   322             Asserts.fail();
   835             Asserts.fail();
   323         } catch (NullPointerException e) {
   836         } catch (NullPointerException e) {
   324             checkMessage("a.getB().getBfromB().to_c.to_d.ar[0][0] = 99; // a.getB().getBfromB().to_c.to_d is null", e.getMessage(),
   837             checkMessage("a.getB().getBfromB().to_c.to_d.ar[0][0] = 99; // a.getB().getBfromB().to_c.to_d is null", e.getMessage(),
   325                          "while trying to read the field 'ar' of a null object loaded from field 'NullPointerExceptionTest$C.to_d' of an object loaded from field 'NullPointerExceptionTest$B.to_c' of an object");
   838                          "'NullPointerExceptionTest$B NullPointerExceptionTest$B.getBfromB().to_c.to_d' is null. " +
       
   839                          "Can not read field 'ar'.");
   326         }
   840         }
   327         a.to_b.to_b.to_c.to_d = new D();
   841         a.to_b.to_b.to_c.to_d = new D();
   328         try {
   842         try {
   329             a.getB().getBfromB().to_c.to_d.ar[0][0] = 99;
   843             a.getB().getBfromB().to_c.to_d.ar[0][0] = 99;
   330             Asserts.fail();
   844             Asserts.fail();
   331         } catch (NullPointerException e) {
   845         } catch (NullPointerException e) {
   332             checkMessage("a.getB().getBfromB().to_c.to_d.ar[0][0] = 99; // a.getB().getBfromB().to_c.to_d.ar is null", e.getMessage(),
   846             checkMessage("a.getB().getBfromB().to_c.to_d.ar[0][0] = 99; // a.getB().getBfromB().to_c.to_d.ar is null", e.getMessage(),
   333                          "while trying to load from a null object array loaded from field 'NullPointerExceptionTest$D.ar' of an object loaded from field 'NullPointerExceptionTest$C.to_d' of an object");
   847                          "'NullPointerExceptionTest$B NullPointerExceptionTest$B.getBfromB().to_c.to_d.ar' is null. " +
       
   848                          "Can not load from null object array.");
   334         }
   849         }
   335         try {
   850         try {
   336             a.getB().getBfromB().getC().getD().ar[0][0] = 99;
   851             a.getB().getBfromB().getC().getD().ar[0][0] = 99;
   337             Asserts.fail();
   852             Asserts.fail();
   338         } catch (NullPointerException e) {
   853         } catch (NullPointerException e) {
   339             checkMessage("a.getB().getBfromB().getC().getD().ar[0][0] = 99; // a.getB().getBfromB().getC().getD().ar is null", e.getMessage(),
   854             checkMessage("a.getB().getBfromB().getC().getD().ar[0][0] = 99; // a.getB().getBfromB().getC().getD().ar is null", e.getMessage(),
   340                          "while trying to load from a null object array loaded from field 'NullPointerExceptionTest$D.ar' of an object returned from 'NullPointerExceptionTest$C.getD()LNullPointerExceptionTest$D;'");
   855                          "'NullPointerExceptionTest$D NullPointerExceptionTest$C.getD().ar' is null. " +
       
   856                          "Can not load from null object array.");
   341         }
   857         }
   342         a.to_b.to_b.to_c.to_d.ar = new int[1][];
   858         a.to_b.to_b.to_c.to_d.ar = new int[1][];
   343         try {
   859         try {
   344             a.getB().getBfromB().to_c.to_d.ar[0][0] = 99;
   860             a.getB().getBfromB().to_c.to_d.ar[0][0] = 99;
   345             Asserts.fail();
   861             Asserts.fail();
   346         } catch (NullPointerException e) {
   862         } catch (NullPointerException e) {
   347             checkMessage("a.getB().getBfromB().to_c.to_d.ar[0][0] = 99; // a.getB().getBfromB().to_c.to_d.ar[0] is null", e.getMessage(),
   863             checkMessage("a.getB().getBfromB().to_c.to_d.ar[0][0] = 99; // a.getB().getBfromB().to_c.to_d.ar[0] is null", e.getMessage(),
   348                          "while trying to store to a null int array loaded from an array (which itself was loaded from field 'NullPointerExceptionTest$D.ar' of an object) with an index loaded from a constant");
   864                          "'NullPointerExceptionTest$B NullPointerExceptionTest$B.getBfromB().to_c.to_d.ar[0]' is null. " +
       
   865                          "Can not store to null int array.");
   349         }
   866         }
   350         try {
   867         try {
   351             a.getB().getBfromB().getC().getD().ar[0][0] = 99;
   868             a.getB().getBfromB().getC().getD().ar[0][0] = 99;
   352             Asserts.fail();
   869             Asserts.fail();
   353         } catch (NullPointerException e) {
   870         } catch (NullPointerException e) {
   354             checkMessage("a.getB().getBfromB().getC().getD().ar[0][0] = 99; // a.getB().getBfromB().getC().getD().ar[0] is null", e.getMessage(),
   871             checkMessage("a.getB().getBfromB().getC().getD().ar[0][0] = 99; // a.getB().getBfromB().getC().getD().ar[0] is null", e.getMessage(),
   355                          "while trying to store to a null int array loaded from an array (which itself was loaded from field 'NullPointerExceptionTest$D.ar' of an object) with an index loaded from a constant");
   872                          "'NullPointerExceptionTest$D NullPointerExceptionTest$C.getD().ar[0]' is null. " +
   356         }
   873                          "Can not store to null int array.");
   357     }
   874         }
   358 
   875     }
       
   876 
       
   877     // Helper method to cause test case.
       
   878     private Object returnNull(String[][] dummy1, int[][][] dummy2, float dummy3) {
       
   879         return null;
       
   880     }
       
   881 
       
   882     // Helper method to cause test case.
       
   883     private NullPointerExceptionTest returnMeAsNull(Throwable dummy1, int dummy2, char dummy3) {
       
   884         return null;
       
   885     }
       
   886 
       
   887     // Helper interface for test cases.
       
   888     static interface DoubleArrayGen {
       
   889         public double[] getArray();
       
   890     }
       
   891 
       
   892     // Helper class for test cases.
       
   893     static class DoubleArrayGenImpl implements DoubleArrayGen {
       
   894         @Override
       
   895         public double[] getArray() {
       
   896             return null;
       
   897         }
       
   898     }
       
   899 
       
   900     // Helper class for test cases.
       
   901     static class NullPointerGenerator {
       
   902         public static Object nullReturner(boolean dummy1) {
       
   903             return null;
       
   904         }
       
   905 
       
   906         public Object returnMyNull(double dummy1, long dummy2, short dummy3) {
       
   907             return null;
       
   908         }
       
   909     }
       
   910 
       
   911     // Helper method to cause test case.
       
   912     public void ImplTestLoadedFromMethod(DoubleArrayGen gen) {
       
   913         try {
       
   914             (gen.getArray())[0] = 1.0;
       
   915             Asserts.fail();
       
   916         } catch (NullPointerException e) {
       
   917             checkMessage("(gen.getArray())[0]", e.getMessage(),
       
   918                          "The return value of 'double[] NullPointerExceptionTest$DoubleArrayGen.getArray()' is null. Can not store to null double array.");
       
   919         }
       
   920     }
       
   921 
       
   922     public void testNullEntity() {
       
   923         int[][] a = new int[820][];
       
   924         
       
   925         test_iload();
       
   926         test_lload();
       
   927         test_fload();
       
   928         // test_dload();
       
   929         test_aload();
       
   930         // aload_0: 'this'
       
   931         try {
       
   932             this.nullInstanceField.nullInstanceField = null;
       
   933             Asserts.fail();
       
   934         } catch (NullPointerException e) {
       
   935             checkMessage("this.nullInstanceField.nullInstanceField = null", e.getMessage(),
       
   936                          "'this.nullInstanceField' is null. Can not write field 'nullInstanceField'.");
       
   937         }
       
   938 
       
   939         // aconst_null
       
   940         try {
       
   941             throw null;
       
   942         } catch (NullPointerException e) {
       
   943             checkMessage("throw null", e.getMessage(),
       
   944                          "'null' is null. Can not throw a null exception object.");
       
   945         }        
       
   946         // iconst_0
       
   947         try {
       
   948             a[0][0] = 77;
       
   949             Asserts.fail();
       
   950         } catch (NullPointerException e) {
       
   951             checkMessage("a[0][0]", e.getMessage(),
       
   952                          (hasDebugInfo ? "'a[0]'" : "'<local1>[0]'") + " is null. " +
       
   953                          "Can not store to null int array.");
       
   954         }
       
   955         // iconst_1
       
   956         try {
       
   957             a[1][0] = 77;
       
   958             Asserts.fail();
       
   959         } catch (NullPointerException e) {
       
   960             checkMessage("a[1][0]", e.getMessage(),
       
   961                          (hasDebugInfo ? "'a[1]'" : "'<local1>[1]'") + " is null. " +
       
   962                          "Can not store to null int array.");
       
   963         }
       
   964         // iconst_2
       
   965         try {
       
   966             a[2][0] = 77;
       
   967             Asserts.fail();
       
   968         } catch (NullPointerException e) {
       
   969             checkMessage("a[2][0]", e.getMessage(),
       
   970                          (hasDebugInfo ? "'a[2]'" : "'<local1>[2]'") + " is null. " +
       
   971                          "Can not store to null int array.");
       
   972         }
       
   973         // iconst_3
       
   974         try {
       
   975             a[3][0] = 77;
       
   976             Asserts.fail();
       
   977         } catch (NullPointerException e) {
       
   978             checkMessage("a[3][0]", e.getMessage(),
       
   979                          (hasDebugInfo ? "'a[3]'" : "'<local1>[3]'") + " is null. " +
       
   980                          "Can not store to null int array.");
       
   981         }
       
   982         // iconst_4
       
   983         try {
       
   984             a[4][0] = 77;
       
   985             Asserts.fail();
       
   986         } catch (NullPointerException e) {
       
   987             checkMessage("a[4][0]", e.getMessage(),
       
   988                          (hasDebugInfo ? "'a[4]'" : "'<local1>[4]'") + " is null. " +
       
   989                          "Can not store to null int array.");
       
   990         }
       
   991         // iconst_5
       
   992         try {
       
   993             a[5][0] = 77;
       
   994             Asserts.fail();
       
   995         } catch (NullPointerException e) {
       
   996             checkMessage("a[5][0]", e.getMessage(),
       
   997                          (hasDebugInfo ? "'a[5]'" : "'<local1>[5]'") + " is null. " +
       
   998                          "Can not store to null int array.");
       
   999         }
       
  1000         // long --> iconst
       
  1001         try {
       
  1002             a[(int)0L][0] = 77;
       
  1003             Asserts.fail();
       
  1004         } catch (NullPointerException e) {
       
  1005             checkMessage("a[(int)0L][0]", e.getMessage(),
       
  1006                          (hasDebugInfo ? "'a[0]'" : "'<local1>[0]'") + " is null. " +
       
  1007                          "Can not store to null int array.");
       
  1008         }
       
  1009         // bipush
       
  1010         try {
       
  1011             a[139 /*0x77*/][0] = 77;
       
  1012             Asserts.fail();
       
  1013         } catch (NullPointerException e) {
       
  1014             checkMessage("a[139][0]", e.getMessage(),
       
  1015                          (hasDebugInfo ? "'a[139]'" : "'<local1>[139]'") + " is null. " +
       
  1016                          "Can not store to null int array.");
       
  1017         }
       
  1018         // sipush
       
  1019         try {
       
  1020             a[819 /*0x333*/][0] = 77;
       
  1021             Asserts.fail();
       
  1022         } catch (NullPointerException e) {
       
  1023             checkMessage("a[819][0]", e.getMessage(),
       
  1024                          (hasDebugInfo ? "'a[819]'" : "'<local1>[819]'") + " is null. " +
       
  1025                          "Can not store to null int array.");
       
  1026         }
       
  1027 
       
  1028         // aaload, with recursive descend.
       
  1029         testArrayChasing();
       
  1030 
       
  1031         // getstatic
       
  1032         try {
       
  1033             Asserts.assertTrue(((float[]) nullStaticField)[0] == 1.0f);
       
  1034             Asserts.fail();
       
  1035         } catch (NullPointerException e) {
       
  1036             checkMessage("((float[]) nullStaticField)[0]", e.getMessage(),
       
  1037                          "'static NullPointerExceptionTest.nullStaticField' is null. Can not load from null float array.");
       
  1038         }
       
  1039 
       
  1040         // getfield, with recursive descend.
       
  1041         testPointerChasing();
       
  1042 
       
  1043         // invokestatic
       
  1044         try {
       
  1045             Asserts.assertTrue(((char[]) NullPointerGenerator.nullReturner(false))[0] == 'A');
       
  1046             Asserts.fail();
       
  1047         } catch (NullPointerException e) {
       
  1048             checkMessage("((char[]) NullPointerGenerator.nullReturner(false))[0]", e.getMessage(),
       
  1049                          "The return value of 'java.lang.Object NullPointerExceptionTest$NullPointerGenerator.nullReturner(boolean)' is null. Can not load from null char array.");
       
  1050         }
       
  1051         // invokevirtual
       
  1052         try {
       
  1053             Asserts.assertTrue(((char[]) (new NullPointerGenerator().returnMyNull(1, 1, (short) 1)))[0] == 'a');
       
  1054             Asserts.fail();
       
  1055         } catch (NullPointerException e) {
       
  1056             checkMessage("((char[]) (new NullPointerGenerator().returnMyNull(1, 1, (short) 1)))[0]", e.getMessage(), 
       
  1057                          "The return value of 'java.lang.Object NullPointerExceptionTest$NullPointerGenerator.returnMyNull(double, long, short)' is null. Can not load from null char array.");
       
  1058         }
       
  1059         // Call with array arguments.
       
  1060         try {
       
  1061             Asserts.assertTrue(((double[]) returnNull(null, null, 1f))[0] == 1.0);
       
  1062             Asserts.fail();
       
  1063         } catch (NullPointerException e) {
       
  1064             checkMessage("((double[]) returnNull(null, null, 1f))[0] ", e.getMessage(),
       
  1065                          "The return value of 'java.lang.Object NullPointerExceptionTest.returnNull(java.lang.String[][], int[][][], float)' is null. Can not load from null double array.");
       
  1066         }
       
  1067         // invokeinterface
       
  1068         ImplTestLoadedFromMethod(new DoubleArrayGenImpl());
       
  1069         try {
       
  1070             returnMeAsNull(null, 1, 'A').dag = null;
       
  1071             Asserts.fail();
       
  1072         } catch (NullPointerException e) {
       
  1073             checkMessage("returnMeAsNull(null, 1, 'A').dag = null", e.getMessage(),
       
  1074                          "The return value of 'NullPointerExceptionTest NullPointerExceptionTest.returnMeAsNull(java.lang.Throwable, int, char)' is null. Can not write field 'dag'.");
       
  1075         }
       
  1076         testMethodChasing();
       
  1077 
       
  1078         // Mixed recursive descend.
       
  1079         testMixedChasing();
       
  1080 
       
  1081     }
       
  1082 
       
  1083 
       
  1084     public void testCreation() throws Exception {
       
  1085         // If allocated with new, the message should not be generated.
       
  1086         Asserts.assertNull(new NullPointerException().getMessage());
       
  1087         String msg = new String("A pointless message.");
       
  1088         Asserts.assertTrue(new NullPointerException(msg).getMessage() == msg);
       
  1089         
       
  1090         // If created via reflection, the message should not be generated.
       
  1091         Exception ex = NullPointerException.class.getDeclaredConstructor().newInstance();
       
  1092         Asserts.assertNull(ex.getMessage());        
       
  1093     }
       
  1094 
       
  1095     public void testNative() throws Exception {
       
  1096         // If NPE is thrown in a native method, the message should
       
  1097         // not be generated.
       
  1098         try {
       
  1099             Class.forName(null);
       
  1100             Asserts.fail();
       
  1101         } catch (NullPointerException e) {
       
  1102             Asserts.assertNull(e.getMessage());
       
  1103         }
       
  1104         
       
  1105     }
   359 
  1106 
   360     // Test we get the same message calling npe.getMessage() twice.
  1107     // Test we get the same message calling npe.getMessage() twice.
   361     public void testSameMessage() throws Exception {
  1108     public void testSameMessage() throws Exception {
   362         Object null_o = null;
  1109         Object null_o = null;
   363         String expectedMsg =
  1110         String expectedMsg =
   364             "while trying to invoke the method 'java.lang.Object.hashCode()I'" +
  1111             (hasDebugInfo ? "'null_o" : "'<local1>") + "' is null. " +
   365             " on a null reference loaded from " +
  1112             "Can not invoke method 'int java.lang.Object.hashCode()'.";
   366             (hasDebugInfo ? "local variable 'null_o'" : "a local variable at slot 1");
       
   367 
  1113 
   368         try {
  1114         try {
   369             null_o.hashCode();
  1115             null_o.hashCode();
   370             Asserts.fail();
  1116             Asserts.fail();
   371         } catch (NullPointerException npe) {
  1117         } catch (NullPointerException npe) {
   372             String msg1 = npe.getMessage();
  1118             String msg1 = npe.getMessage();
   373             checkMessage("null_o.hashCode()", msg1, expectedMsg);
  1119             checkMessage("null_o.hashCode()", msg1, expectedMsg);
   374             String msg2 = npe.getMessage();
  1120             String msg2 = npe.getMessage();
   375             Asserts.assertTrue(msg1.equals(msg2));
  1121             Asserts.assertTrue(msg1.equals(msg2));
   376             // It was decided that getMessage should generate the
  1122             // It was decided that getMessage should generate the
   377             // message anew on every call, so this does not hold any more.
  1123             // message anew on every call, so this does not hold.
       
  1124             //Asserts.assertTrue(msg1 == msg2);
   378             Asserts.assertFalse(msg1 == msg2);
  1125             Asserts.assertFalse(msg1 == msg2);
   379         }
  1126         }
   380     }
  1127     }
   381 
  1128 
   382     /**
  1129     public void testSerialization() throws Exception {
   383      *
       
   384      */
       
   385     public void testCreationViaNew() {
       
   386         Asserts.assertNull(new NullPointerException().getMessage());
       
   387     }
       
   388 
       
   389     /**
       
   390      * @throws Exception
       
   391      */
       
   392     public void testCreationViaReflection() throws Exception {
       
   393         Exception ex = NullPointerException.class.getDeclaredConstructor().newInstance();
       
   394         Asserts.assertNull(ex.getMessage());
       
   395     }
       
   396 
       
   397     /**
       
   398      * @throws Exception
       
   399      */
       
   400     public void testCreationViaSerialization() throws Exception {
       
   401         // NPE without message.
  1130         // NPE without message.
   402         Object o1 = new NullPointerException();
  1131         Object o1 = new NullPointerException();
   403         ByteArrayOutputStream bos1 = new ByteArrayOutputStream();
  1132         ByteArrayOutputStream bos1 = new ByteArrayOutputStream();
   404         ObjectOutputStream oos1 = new ObjectOutputStream(bos1);
  1133         ObjectOutputStream oos1 = new ObjectOutputStream(bos1);
   405         oos1.writeObject(o1);
  1134         oos1.writeObject(o1);
   427             null_o3.hashCode();
  1156             null_o3.hashCode();
   428             Asserts.fail();
  1157             Asserts.fail();
   429         } catch (NullPointerException npe3) {
  1158         } catch (NullPointerException npe3) {
   430             o3 = npe3;
  1159             o3 = npe3;
   431             msg3 = npe3.getMessage();
  1160             msg3 = npe3.getMessage();
   432             checkMessage("null_o3.hashCode()", msg3, "while trying to invoke the method 'java.lang.Object.hashCode()I'" +
  1161             checkMessage("null_o3.hashCode()", msg3, 
   433                                  " on a null reference loaded from " +
  1162                          (hasDebugInfo ? "'null_o3'" : "'<local14>'") + " is null. " +
   434                                  (hasDebugInfo ? "local variable 'null_o3'" : "a local variable at slot 14"));
  1163                          "Can not invoke method 'int java.lang.Object.hashCode()'.");
   435         }
  1164         }
   436         ByteArrayOutputStream bos3 = new ByteArrayOutputStream();
  1165         ByteArrayOutputStream bos3 = new ByteArrayOutputStream();
   437         ObjectOutputStream oos3 = new ObjectOutputStream(bos3);
  1166         ObjectOutputStream oos3 = new ObjectOutputStream(bos3);
   438         oos3.writeObject(o3);
  1167         oos3.writeObject(o3);
   439         ByteArrayInputStream bis3 = new ByteArrayInputStream(bos3.toByteArray());
  1168         ByteArrayInputStream bis3 = new ByteArrayInputStream(bos3.toByteArray());
   444         // be recovered by serialization.
  1173         // be recovered by serialization.
   445         //Asserts.assertEquals(ex3.getMessage(), msg3);
  1174         //Asserts.assertEquals(ex3.getMessage(), msg3);
   446         Asserts.assertEquals(ex3.getMessage(), null);
  1175         Asserts.assertEquals(ex3.getMessage(), null);
   447     }
  1176     }
   448 
  1177 
   449     /**
  1178     public void testComplexMessages() {
   450      *
       
   451      */
       
   452     @SuppressWarnings("null")
       
   453     public void testLoadedFromLocalVariable1() {
       
   454         Object o = null;
       
   455 
       
   456         try {
       
   457             o.hashCode();
       
   458             Asserts.fail();
       
   459         } catch (NullPointerException e) {
       
   460             checkMessage("o.hashCode()", e.getMessage(), "while trying to invoke the method 'java.lang.Object.hashCode()I' on a null reference loaded from " + (hasDebugInfo ? "local variable 'o'" : "a local variable at slot 1"));
       
   461         }
       
   462     }
       
   463 
       
   464     /**
       
   465      *
       
   466      */
       
   467     @SuppressWarnings("null")
       
   468     public void testLoadedFromLocalVariable2() {
       
   469         Exception[] myVariable = null;
       
   470 
       
   471         try {
       
   472             Asserts.assertNull(myVariable[0]);
       
   473             Asserts.fail();
       
   474         } catch (NullPointerException e) {
       
   475             checkMessage("myVariable[0]", e.getMessage(), "while trying to load from a null object array loaded from " + (hasDebugInfo ? "local variable 'myVariable'" : "a local variable at slot 1"));
       
   476         }
       
   477     }
       
   478 
       
   479     /**
       
   480      *
       
   481      */
       
   482     @SuppressWarnings("null")
       
   483     public void testLoadedFromLocalVariable3() {
       
   484         Exception[] myVariable = null;
       
   485 
       
   486         try {
       
   487             myVariable[0] = null;
       
   488             Asserts.fail();
       
   489         } catch (NullPointerException e) {
       
   490             checkMessage("myVariable[0] = null", e.getMessage(), "while trying to store to a null object array loaded from " + (hasDebugInfo ? "local variable 'myVariable'" : "a local variable at slot 1"));
       
   491         }
       
   492     }
       
   493 
       
   494     /**
       
   495      *
       
   496      */
       
   497     @SuppressWarnings("null")
       
   498     public void testLoadedFromLocalVariable4() {
       
   499         Exception[] myVariable\u0096 = null;
       
   500 
       
   501         try {
       
   502             Asserts.assertTrue(myVariable\u0096.length == 0);
       
   503             Asserts.fail();
       
   504         } catch (NullPointerException e) {
       
   505             checkMessage("myVariable\u0096.length", e.getMessage(), "while trying to get the length of a null array loaded from " + (hasDebugInfo ? "local variable 'myVariable'" : "a local variable at slot 1"));
       
   506         }
       
   507     }
       
   508 
       
   509     /**
       
   510      * @throws Exception
       
   511      */
       
   512     @SuppressWarnings("null")
       
   513     public void testLoadedFromLocalVariable5() throws Exception {
       
   514         Exception myException = null;
       
   515 
       
   516         try {
       
   517             throw myException;
       
   518         } catch (NullPointerException e) {
       
   519             checkMessage("throw myException", e.getMessage(), "while trying to throw a null exception object loaded from " + (hasDebugInfo ? "local variable 'myException'" : "a local variable at slot 1"));
       
   520         }
       
   521     }
       
   522 
       
   523     /**
       
   524      *
       
   525      */
       
   526     @SuppressWarnings("null")
       
   527     public void testLoadedFromLocalVariable6() {
       
   528         byte[] myVariable = null;
       
   529         int my_index = 1;
       
   530 
       
   531         try {
       
   532             Asserts.assertTrue(myVariable[my_index] == 0);
       
   533             Asserts.fail();
       
   534         } catch (NullPointerException e) {
       
   535             checkMessage("myVariable[my_index]", e.getMessage(), "while trying to load from a null byte (or boolean) array loaded from " + (hasDebugInfo ? "local variable 'myVariable'" : "a local variable at slot 1"));
       
   536         }
       
   537     }
       
   538 
       
   539     /**
       
   540      *
       
   541      */
       
   542     @SuppressWarnings("null")
       
   543     public void testLoadedFromLocalVariable7() {
       
   544         byte[] myVariable = null;
       
   545 
       
   546         try {
       
   547             myVariable[System.out.hashCode()] = (byte) 0;
       
   548             Asserts.fail();
       
   549         } catch (NullPointerException e) {
       
   550             checkMessage("myVariable[System.out.hashCode()]", e.getMessage(), "while trying to store to a null byte (or boolean) array loaded from " + (hasDebugInfo ? "local variable 'myVariable'" : "a local variable at slot 1"));
       
   551         }
       
   552     }
       
   553 
       
   554     /**
       
   555      *
       
   556      */
       
   557     public void testLoadedFromMethod1() {
       
   558         try {
       
   559             Asserts.assertTrue(((char[]) NullPointerGenerator.nullReturner(false))[0] == 'A');
       
   560             Asserts.fail();
       
   561         } catch (NullPointerException e) {
       
   562             checkMessage("((char[]) NullPointerGenerator.nullReturner(false))[0]", e.getMessage(), "while trying to load from a null char array returned from 'NullPointerExceptionTest$NullPointerGenerator.nullReturner(Z)Ljava/lang/Object;'");
       
   563         }
       
   564     }
       
   565 
       
   566     /**
       
   567      *
       
   568      */
       
   569     public void testLoadedFromMethod2() {
       
   570         try {
       
   571             Asserts.assertTrue(((char[]) (new NullPointerGenerator().returnMyNull(1, 1, (short) 1)))[0] == 'a');
       
   572             Asserts.fail();
       
   573         } catch (NullPointerException e) {
       
   574             checkMessage("((char[]) (new NullPointerGenerator().returnMyNull(1, 1, (short) 1)))[0]", e.getMessage(), "while trying to load from a null char array returned from 'NullPointerExceptionTest$NullPointerGenerator.returnMyNull(DJS)Ljava/lang/Object;'");
       
   575         }
       
   576     }
       
   577 
       
   578     /**
       
   579      *
       
   580      */
       
   581     public void testLoadedFromMethod3() {
       
   582         try {
       
   583             Asserts.assertTrue(((double[]) returnNull(null, null, 1f))[0] == 1.0);
       
   584             Asserts.fail();
       
   585         } catch (NullPointerException e) {
       
   586             checkMessage("((double[]) returnNull(null, null, 1f))[0] ", e.getMessage(), "while trying to load from a null double array returned from 'NullPointerExceptionTest.returnNull([[Ljava/lang/String;[[[IF)Ljava/lang/Object;'");
       
   587         }
       
   588     }
       
   589 
       
   590     /**
       
   591      *
       
   592      */
       
   593     public void testLoadedFromMethod4() {
       
   594         ImplTestLoadedFromMethod4(new DoubleArrayGenImpl());
       
   595     }
       
   596 
       
   597     /**
       
   598      * @param gen
       
   599      */
       
   600     public void ImplTestLoadedFromMethod4(DoubleArrayGen gen) {
       
   601         try {
       
   602             (gen.getArray())[0] = 1.0;
       
   603             Asserts.fail();
       
   604         } catch (NullPointerException e) {
       
   605             checkMessage("(gen.getArray())[0]", e.getMessage(), "while trying to store to a null double array returned from 'NullPointerExceptionTest$DoubleArrayGen.getArray()[D'");
       
   606         }
       
   607     }
       
   608 
       
   609     /**
       
   610      *
       
   611      */
       
   612     public void testLoadedFromMethod5() {
       
   613         try {
       
   614             returnMeAsNull(null, 1, 'A').dag = null;
       
   615             Asserts.fail();
       
   616         } catch (NullPointerException e) {
       
   617             checkMessage("returnMeAsNull(null, 1, 'A').dag = null", e.getMessage(), "while trying to write the field 'NullPointerExceptionTest.dag' of a null object returned from 'NullPointerExceptionTest.returnMeAsNull(Ljava/lang/Throwable;IC)LNullPointerExceptionTest;'");
       
   618         }
       
   619         /*
       
   620         try {
       
   621             returnMeAsNull(null, 1, 'A').dag.dag = null;
       
   622             Asserts.fail();
       
   623         } catch (NullPointerException e) {
       
   624             checkMessage("returnMeAsNull(null, 1, 'A').dag.dag = null", e.getMessage(), "while trying to write the field 'NullPointerExceptionTest.dag' of a null object returned from 'NullPointerExceptionTest.returnMeAsNull(Ljava/lang/Throwable;IC)LNullPointerExceptionTest;'");
       
   625         }
       
   626         */
       
   627     }
       
   628 
       
   629     /**
       
   630      *
       
   631      */
       
   632     @SuppressWarnings("null")
       
   633     public void testLoadedFromMethod6() {
       
   634         short[] sa = null;
       
   635 
       
   636         try {
       
   637             Asserts.assertTrue(sa[0] == (short) 1);
       
   638             Asserts.fail();
       
   639         } catch (NullPointerException e) {
       
   640             checkMessage("sa[0]", e.getMessage(), "while trying to load from a null short array loaded from " + (hasDebugInfo ? "local variable 'sa'" : "a local variable at slot 1"));
       
   641         }
       
   642     }
       
   643 
       
   644     /**
       
   645      *
       
   646      */
       
   647     @SuppressWarnings("null")
       
   648     public void testLoadedFromMethod7() {
       
   649         short[] sa = null;
       
   650 
       
   651         try {
       
   652             sa[0] = 1;
       
   653             Asserts.fail();
       
   654         } catch (NullPointerException e) {
       
   655             checkMessage("sa[0] = 1", e.getMessage(), "while trying to store to a null short array loaded from " + (hasDebugInfo ? "local variable 'sa'" : "a local variable at slot 1"));
       
   656         }
       
   657     }
       
   658 
       
   659     /**
       
   660      *
       
   661      */
       
   662     public void testLoadedFromStaticField1() {
       
   663         try {
       
   664             Asserts.assertTrue(((float[]) nullStaticField)[0] == 1.0f);
       
   665             Asserts.fail();
       
   666         } catch (NullPointerException e) {
       
   667             checkMessage("((float[]) nullStaticField)[0]", e.getMessage(), "while trying to load from a null float array loaded from static field 'NullPointerExceptionTest.nullStaticField'");
       
   668         }
       
   669     }
       
   670 
       
   671     /**
       
   672      *
       
   673      */
       
   674     public void testLoadedFromStaticField2() {
       
   675         try {
       
   676             ((float[]) nullStaticField)[0] = 1.0f;
       
   677             Asserts.fail();
       
   678         } catch (NullPointerException e) {
       
   679             checkMessage("((float[]) nullStaticField)[0] = 1.0f", e.getMessage(), "while trying to store to a null float array loaded from static field 'NullPointerExceptionTest.nullStaticField'");
       
   680         }
       
   681     }
       
   682 
       
   683     /**
       
   684      *
       
   685      */
       
   686     public void testLoadedFromStaticField3() {
       
   687         try {
       
   688             Asserts.assertTrue(staticArray[0][0][0][0] == 1);
       
   689             Asserts.fail();
       
   690         } catch (NullPointerException e) {
       
   691             checkMessage("staticArray[0][0][0][0] // staticArray[0][0][0] is null.", e.getMessage(), "while trying to load from a null int array loaded from an array (which itself was loaded from an array) with an index loaded from a constant");
       
   692         }
       
   693     }
       
   694 
       
   695     /**
       
   696      *
       
   697      */
       
   698     public void testLoadedFromStaticField4(int myIdx, int pos) {
       
   699         try {
       
   700             staticArray[0][0][pos][myIdx] = 2;
       
   701             Asserts.fail();
       
   702         } catch (NullPointerException e) {
       
   703             checkMessage(" staticArray[0][0][pos][myIdx] = 2", e.getMessage(), "while trying to store to a null int array loaded from an array (which itself was loaded from an array) with an index loaded from " + (hasDebugInfo ? "local variable 'pos'" : "the parameter nr. 2 of the method"));
       
   704         }
       
   705     }
       
   706 
       
   707     /**
       
   708      *
       
   709      */
       
   710     public void testLoadedFromStaticField5() {
       
   711         try {
       
   712             Asserts.assertTrue(staticLongArray[0][0] == 1L);
       
   713         } catch (NullPointerException e) {
       
   714             checkMessage("staticLongArray[0][0]", e.getMessage(), "while trying to load from a null long array loaded from an array (which itself was loaded from static field 'NullPointerExceptionTest.staticLongArray') with an index loaded from a constant");
       
   715         }
       
   716     }
       
   717 
       
   718     /**
       
   719      * Test bipush for index.
       
   720      */
       
   721     public void testLoadedFromStaticField5a() {
       
   722         try {
       
   723             Asserts.assertTrue(staticLongArray[139 /*0x77*/][0] == 1L);
       
   724         } catch (NullPointerException e) {
       
   725             checkMessage("staticLongArray[139][0]", e.getMessage(), "while trying to load from a null long array loaded from an array (which itself was loaded from static field 'NullPointerExceptionTest.staticLongArray') with an index loaded from a constant");
       
   726         }
       
   727     }
       
   728 
       
   729     /**
       
   730      * Test sipush for index.
       
   731      */
       
   732     public void testLoadedFromStaticField5b() {
       
   733         try {
       
   734             Asserts.assertTrue(staticLongArray[819 /*0x333*/][0] == 1L);
       
   735         } catch (NullPointerException e) {
       
   736             checkMessage("staticLongArray[819][0]",  e.getMessage(), "while trying to load from a null long array loaded from an array (which itself was loaded from static field 'NullPointerExceptionTest.staticLongArray') with an index loaded from a constant");
       
   737         }
       
   738     }
       
   739 
       
   740     /**
       
   741      *
       
   742      */
       
   743     public void testLoadedFromStaticField6() {
       
   744         try {
  1179         try {
   745             staticLongArray[0][0] = 2L;
  1180             staticLongArray[0][0] = 2L;
   746             Asserts.fail();
  1181             Asserts.fail();
   747         } catch (NullPointerException e) {
  1182         } catch (NullPointerException e) {
   748             checkMessage("staticLongArray[0][0] = 2L", e.getMessage(), "while trying to store to a null long array loaded from an array (which itself was loaded from static field 'NullPointerExceptionTest.staticLongArray') with an index loaded from a constant");
  1183             checkMessage("staticLongArray[0][0] = 2L", e.getMessage(),
   749         }
  1184                          "'static NullPointerExceptionTest.staticLongArray[0]' is null. " +
   750     }
  1185                          "Can not store to null long array.");
   751 
  1186         }
   752     /**
  1187 
   753      *
       
   754      */
       
   755     public void testLoadedFromInstanceField1() {
       
   756         try {
  1188         try {
   757             Asserts.assertTrue(this.nullInstanceField.nullInstanceField == null);
  1189             Asserts.assertTrue(this.nullInstanceField.nullInstanceField == null);
   758             Asserts.fail();
  1190             Asserts.fail();
   759         } catch (NullPointerException e) {
  1191         } catch (NullPointerException e) {
   760             checkMessage("this.nullInstanceField.nullInstanceField", e.getMessage(), "while trying to read the field 'nullInstanceField' of a null object loaded from field 'NullPointerExceptionTest.nullInstanceField' of an object loaded from 'this'");
  1192             checkMessage("this.nullInstanceField.nullInstanceField", e.getMessage(),
   761         }
  1193                          "'this.nullInstanceField' is null. " +
   762     }
  1194                          "Can not read field 'nullInstanceField'.");
   763 
  1195         }
   764     /**
  1196 
   765      *
  1197         try {
   766      */
  1198             NullPointerExceptionTest obj = this;
   767     public void testLoadedFromInstanceField2() {
       
   768         try {
       
   769             this.nullInstanceField.nullInstanceField = null;
       
   770             Asserts.fail();
       
   771         } catch (NullPointerException e) {
       
   772             checkMessage("this.nullInstanceField.nullInstanceField = null", e.getMessage(), "while trying to write the field 'NullPointerExceptionTest.nullInstanceField' of a null object loaded from field 'NullPointerExceptionTest.nullInstanceField' of an object loaded from 'this'");
       
   773         }
       
   774     }
       
   775 
       
   776     /**
       
   777      *
       
   778      */
       
   779     public void testLoadedFromInstanceField3() {
       
   780         NullPointerExceptionTest obj = this;
       
   781 
       
   782         try {
       
   783             Asserts.assertNull(obj.dag.getArray().clone());
  1199             Asserts.assertNull(obj.dag.getArray().clone());
   784             Asserts.fail();
  1200             Asserts.fail();
   785         } catch (NullPointerException e) {
  1201         } catch (NullPointerException e) {
   786             checkMessage("obj.dag.getArray().clone()", e.getMessage(), "while trying to invoke the method 'NullPointerExceptionTest$DoubleArrayGen.getArray()[D' on a null reference loaded from field 'NullPointerExceptionTest.dag' of an object loaded from " + (hasDebugInfo ? "local variable 'obj'" : "a local variable at slot 1"));
  1202             checkMessage("obj.dag.getArray().clone()", e.getMessage(),
   787         }
  1203                          (hasDebugInfo ? "'obj" : "'<local1>") + ".dag' is null. " +
   788     }
  1204                          "Can not invoke method 'double[] NullPointerExceptionTest$DoubleArrayGen.getArray()'.");
   789 
  1205         }
   790     /**
  1206         try {
   791      *
  1207             int indexes[] = new int[1];
   792      */
  1208             NullPointerExceptionTest[] objs = new NullPointerExceptionTest[] {this};
   793     public void testLoadedFromInstanceField4() {
       
   794         int indexes[] = new int[1];
       
   795 
       
   796         NullPointerExceptionTest[] objs = new NullPointerExceptionTest[] {this};
       
   797 
       
   798         try {
       
   799             Asserts.assertNull(objs[indexes[0]].nullInstanceField.returnNull(null, null, 1f));
  1209             Asserts.assertNull(objs[indexes[0]].nullInstanceField.returnNull(null, null, 1f));
   800             Asserts.fail();
  1210             Asserts.fail();
   801         } catch (NullPointerException e) {
  1211         } catch (NullPointerException e) {
   802             checkMessage("objs[indexes[0]].nullInstanceField.returnNull(null, null, 1f", e.getMessage(), "while trying to invoke the method 'NullPointerExceptionTest.returnNull([[Ljava/lang/String;[[[IF)Ljava/lang/Object;' on a null reference loaded from field 'NullPointerExceptionTest.nullInstanceField' of an object loaded from an array");
  1212             checkMessage("objs[indexes[0]].nullInstanceField.returnNull(null, null, 1f)", e.getMessage(),
   803         }
  1213                          (hasDebugInfo ? "'objs[indexes" : "'<local2>[<local1>") + "[0]].nullInstanceField' is null. " +
   804     }
  1214                          "Can not invoke method 'java.lang.Object NullPointerExceptionTest.returnNull(java.lang.String[][], int[][][], float)'.");
   805 
  1215         }
   806     /**
  1216 
   807      *
  1217         try {
   808      */
  1218             int indexes[] = new int[1];
   809     public void testLoadedFromInstanceField5() {
  1219             NullPointerExceptionTest[][] objs =
   810         int indexes[] = new int[1];
  1220                 new NullPointerExceptionTest[][] {new NullPointerExceptionTest[] {this}};
   811 
       
   812         NullPointerExceptionTest[] objs = new NullPointerExceptionTest[] {this};
       
   813 
       
   814         try {
       
   815             Asserts.assertNull(objs[indexes[0]].nullInstanceField.toString().toCharArray().clone());
       
   816         } catch (NullPointerException e) {
       
   817             checkMessage("objs[indexes[0]].nullInstanceField.toString().toCharArray().clone()", e.getMessage(), "while trying to invoke the method 'java.lang.Object.toString()Ljava/lang/String;' on a null reference loaded from field 'NullPointerExceptionTest.nullInstanceField' of an object loaded from an array");
       
   818         }
       
   819     }
       
   820 
       
   821     /**
       
   822      *
       
   823      */
       
   824     public void testLoadedFromInstanceField6() {
       
   825         int indexes[] = new int[1];
       
   826 
       
   827         NullPointerExceptionTest[][] objs =
       
   828             new NullPointerExceptionTest[][] {new NullPointerExceptionTest[] {this}};
       
   829 
       
   830         try {
       
   831             // Check monitorenter only, since we cannot probe monitorexit from Java.
       
   832             synchronized (objs[indexes[0]][0].nullInstanceField) {
  1221             synchronized (objs[indexes[0]][0].nullInstanceField) {
   833                 Asserts.fail();
  1222                 Asserts.fail();
   834             }
  1223             }
   835         } catch (NullPointerException e) {
  1224         } catch (NullPointerException e) {
   836             checkMessage("synchronized (objs[indexes[0]][0].nullInstanceField)", e.getMessage(), "while trying to enter a null monitor loaded from field 'NullPointerExceptionTest.nullInstanceField' of an object loaded from an array");
  1225             checkMessage("synchronized (objs[indexes[0]][0].nullInstanceField)", e.getMessage(),
   837         }
  1226                          (hasDebugInfo ? "'objs[indexes" : "'<local2>[<local1>" ) + "[0]][0].nullInstanceField' is null. " +
   838     }
  1227                          "Can not enter a null monitor.");
   839 
  1228         }
   840     /**
  1229     }
   841      * @throws ClassNotFoundException
  1230 
   842      */
  1231     // Generates:
   843     public void testInNative() throws ClassNotFoundException {
  1232     // class E implements E0 {
   844         try {
  1233     //     public int throwNPE(F f) {
   845             Class.forName(null);
  1234     //         return f.i;
   846             Asserts.fail();
  1235     //     }
   847         } catch (NullPointerException e) {
  1236     // }
   848             Asserts.assertNull(e.getMessage());
  1237     static byte[] generateTestClass() {
   849         }
  1238         ClassWriter cw = new ClassWriter(0);
   850     }
  1239         MethodVisitor mv;
   851 
  1240 
   852     private Object returnNull(String[][] dummy1, int[][][] dummy2, float dummy3) {
  1241         cw.visit(57, ACC_SUPER, "E", null, "java/lang/Object", new String[] { "E0" });
   853         return null;
  1242 
   854     }
  1243         {
   855 
  1244             mv = cw.visitMethod(0, "<init>", "()V", null, null);
   856     private NullPointerExceptionTest returnMeAsNull(Throwable dummy1, int dummy2, char dummy3){
  1245             mv.visitCode();
   857         return null;
  1246             mv.visitVarInsn(ALOAD, 0);
   858     }
  1247             mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
   859 
  1248             mv.visitInsn(RETURN);
   860     static interface DoubleArrayGen {
  1249             mv.visitMaxs(1, 1);
   861         public double[] getArray();
  1250             mv.visitEnd();
   862     }
  1251         }
   863 
  1252 
   864     static class DoubleArrayGenImpl implements DoubleArrayGen {
  1253         {
   865         @Override
  1254             mv = cw.visitMethod(ACC_PUBLIC, "throwNPE", "(LF;)I", null, null);
   866         public double[] getArray() {
  1255             mv.visitCode();
   867             return null;
  1256             Label label0 = new Label();
   868         }
  1257             mv.visitLabel(label0);
   869     }
  1258             mv.visitLineNumber(118, label0);
   870 
  1259             mv.visitVarInsn(ALOAD, 1);
   871     static class NullPointerGenerator {
  1260             mv.visitFieldInsn(GETFIELD, "F", "i", "I");
   872         public static Object nullReturner(boolean dummy1) {
  1261             mv.visitInsn(IRETURN);
   873             return null;
  1262             Label label1 = new Label();
   874         }
  1263             mv.visitLabel(label1);
   875 
  1264             mv.visitLocalVariable("this", "LE;", null, label0, label1, 0);
   876         public Object returnMyNull(double dummy1, long dummy2, short dummy3) {
  1265             mv.visitLocalVariable("f", "LE;", null, label0, label1, 1);
   877             return null;
  1266             mv.visitMaxs(1, 2);
   878         }
  1267             mv.visitEnd();
   879     }
  1268         }
   880 
  1269         cw.visitEnd();
   881     /**
  1270 
   882      *
  1271         return cw.toByteArray();
   883      */
  1272     }
   884     public void testMissingLocalVariableTable() {
  1273 
   885         doTestMissingLocalVariableTable(names);
  1274     // Tests that a class generated on the fly is handled properly.
   886 
  1275     public void testGeneratedCode() throws Exception {
   887         String[] expectedHasDebugInfoGoodNames = new String[] {
  1276         byte[] classBytes = generateTestClass();
   888             "while trying to invoke the method 'java.lang.Object.hashCode()I' on a null reference " +
  1277         Lookup lookup = lookup();
   889                 "loaded from field 'NullPointerExceptionTest.nullInstanceField' " +
  1278         Class<?> clazz = lookup.defineClass(classBytes);
   890                 "of an object loaded from 'this'",
  1279         E0 e = (E0) clazz.getDeclaredConstructor().newInstance();
   891             "while trying to invoke the method 'java.lang.Object.hashCode()I' on a null reference loaded from " +
  1280         try {
   892                 "local variable 'a1'",
  1281             e.throwNPE(null);
   893             "while trying to invoke the method 'java.lang.Object.hashCode()I' on a null reference loaded from " +
  1282         } catch (NullPointerException ex) {
   894                 "local variable 'o1'",
  1283             checkMessage("return f.i;",
   895             "while trying to invoke the method 'java.lang.Object.hashCode()I' on a null reference loaded from " +
  1284                          ex.getMessage(),
   896                 "local variable 'aa1'"
  1285                          "'f' is null. Can not read field 'i'.");
   897         };
       
   898 
       
   899         String[] expectedNoDebugInfoGoodNames = new String[] {
       
   900             "while trying to invoke the method 'java.lang.Object.hashCode()I' on a null reference " +
       
   901                 "loaded from field 'NullPointerExceptionTest.nullInstanceField' " +
       
   902                 "of an object loaded from 'this'",
       
   903             "while trying to invoke the method 'java.lang.Object.hashCode()I' on a null reference loaded from " +
       
   904                 "the parameter nr. 5 of the method",
       
   905             "while trying to invoke the method 'java.lang.Object.hashCode()I' on a null reference loaded from " +
       
   906                 "the parameter nr. 2 of the method",
       
   907             "while trying to invoke the method 'java.lang.Object.hashCode()I' on a null reference loaded from " +
       
   908                 "the parameter nr. 9 of the method"
       
   909         };
       
   910 
       
   911         String[] expectedNames;
       
   912         if (hasDebugInfo) {
       
   913             expectedNames = expectedHasDebugInfoGoodNames;
       
   914         } else {
       
   915             expectedNames = expectedNoDebugInfoGoodNames;
       
   916         }
       
   917 
       
   918         // The two lists of messages should have the same length.
       
   919         Asserts.assertEquals(names.size(), expectedNames.length);
       
   920 
       
   921         for (int i = 0; i < expectedNames.length; ++i) {
       
   922             // GLGLGL not for now Asserts.assertEquals(names.get(i), expectedNames[i]);
       
   923         }
       
   924     }
       
   925 
       
   926     private void doTestMissingLocalVariableTable(ArrayList<String> names) {
       
   927         curr = names;
       
   928         doTestMissingLocalVariableTable1();
       
   929         doTestMissingLocalVariableTable2(-1, null, false, 0.0, null, 0.1f, (byte) 0, (short) 0, null);
       
   930     }
       
   931 
       
   932     private void doTestMissingLocalVariableTable1() {
       
   933         try {
       
   934             this.nullInstanceField.hashCode();
       
   935             Asserts.fail();
       
   936         } catch (NullPointerException e) {
       
   937             curr.add(e.getMessage());
       
   938         }
       
   939     }
       
   940 
       
   941     private void doTestMissingLocalVariableTable2(long l1, Object o1, boolean z1, double d1, Object[] a1,
       
   942             float f1, byte b1, short s1, Object[][] aa1) {
       
   943         try {
       
   944             a1.hashCode();
       
   945             Asserts.fail();
       
   946         }
       
   947         catch (NullPointerException e) {
       
   948             curr.add(e.getMessage());
       
   949         }
       
   950 
       
   951         try {
       
   952             o1.hashCode();
       
   953             Asserts.fail();
       
   954         }
       
   955         catch (NullPointerException e) {
       
   956             curr.add(e.getMessage());
       
   957         }
       
   958 
       
   959         try {
       
   960             aa1.hashCode();
       
   961             Asserts.fail();
       
   962         }
       
   963         catch (NullPointerException e) {
       
   964             curr.add(e.getMessage());
       
   965         }
       
   966     }
       
   967 
       
   968     /**
       
   969      *
       
   970      */
       
   971     @SuppressWarnings("null")
       
   972     public void testNullMessages() {
       
   973         boolean[] za1 = null;
       
   974         byte[] ba1 = null;
       
   975         short[] sa1 = null;
       
   976         char[] ca1 = null;
       
   977         int[] ia1 = null;
       
   978         long[] la1 = null;
       
   979         float[] fa1 = null;
       
   980         double[] da1 = null;
       
   981         Object[] oa1 = null;
       
   982 
       
   983         Object[][] oa2 = new Object[2][];
       
   984         oa2[1] = oa1;
       
   985 
       
   986         try {
       
   987             System.out.println(oa2[1][0]);
       
   988             Asserts.fail();
       
   989         } catch (NullPointerException e) {
       
   990             checkMessage("oa2[1][0]", e.getMessage(),
       
   991                                  "while trying to load from a null object array loaded from an array " +
       
   992                                  "(which itself was loaded from " +
       
   993                                  (hasDebugInfo ? "local variable 'oa2'" : "a local variable at slot 10") + ") " +
       
   994                                  "with an index loaded from a constant");
       
   995         }
       
   996 
       
   997 
       
   998         try {
       
   999             System.out.println(za1[0]);
       
  1000             Asserts.fail();
       
  1001         } catch (NullPointerException e) {
       
  1002             checkMessage("za1[0]", e.getMessage(),
       
  1003                                  "while trying to load from a null byte (or boolean) array loaded from " +
       
  1004                                  (hasDebugInfo ? "local variable 'za1'" : "a local variable at slot 1"));
       
  1005         }
       
  1006 
       
  1007         try {
       
  1008             System.out.println(ba1[0]);
       
  1009             Asserts.fail();
       
  1010         } catch (NullPointerException e) {
       
  1011             checkMessage("ba1[0]", e.getMessage(),
       
  1012                                  "while trying to load from a null byte (or boolean) array loaded from " +
       
  1013                                  (hasDebugInfo ? "local variable 'ba1'" : "a local variable at slot 2"));
       
  1014         }
       
  1015 
       
  1016         try {
       
  1017             System.out.println(sa1[0]);
       
  1018             Asserts.fail();
       
  1019         } catch (NullPointerException e) {
       
  1020             checkMessage("sa1[0]", e.getMessage(),
       
  1021                                  "while trying to load from a null short array loaded from " +
       
  1022                                  (hasDebugInfo ? "local variable 'sa1'" : "a local variable at slot 3"));
       
  1023         }
       
  1024 
       
  1025         try {
       
  1026             System.out.println(ca1[0]);
       
  1027             Asserts.fail();
       
  1028         } catch (NullPointerException e) {
       
  1029             checkMessage("ca1[0]", e.getMessage(),
       
  1030                                  "while trying to load from a null char array loaded from " +
       
  1031                                  (hasDebugInfo ? "local variable 'ca1'" : "a local variable at slot 4"));
       
  1032         }
       
  1033 
       
  1034         try {
       
  1035             System.out.println(ia1[0]);
       
  1036             Asserts.fail();
       
  1037         } catch (NullPointerException e) {
       
  1038             checkMessage("ia1[0]", e.getMessage(),
       
  1039                                  "while trying to load from a null int array loaded from " +
       
  1040                                  (hasDebugInfo ? "local variable 'ia1'" : "a local variable at slot 5"));
       
  1041         }
       
  1042 
       
  1043         try {
       
  1044             System.out.println(la1[0]);
       
  1045             Asserts.fail();
       
  1046         } catch (NullPointerException e) {
       
  1047             checkMessage("la1[0]", e.getMessage(),
       
  1048                                  "while trying to load from a null long array loaded from " +
       
  1049                                  (hasDebugInfo ? "local variable 'la1'" : "a local variable at slot 6"));
       
  1050         }
       
  1051 
       
  1052         try {
       
  1053             System.out.println(fa1[0]);
       
  1054             Asserts.fail();
       
  1055         } catch (NullPointerException e) {
       
  1056             checkMessage("fa1[0]", e.getMessage(),
       
  1057                                  "while trying to load from a null float array loaded from " +
       
  1058                                  (hasDebugInfo ? "local variable 'fa1'" : "a local variable at slot 7"));
       
  1059         }
       
  1060 
       
  1061         try {
       
  1062             System.out.println(da1[0]);
       
  1063             Asserts.fail();
       
  1064         } catch (NullPointerException e) {
       
  1065             checkMessage("da1[0]", e.getMessage(),
       
  1066                                  "while trying to load from a null double array loaded from " +
       
  1067                                  (hasDebugInfo ? "local variable 'da1'" : "a local variable at slot 8"));
       
  1068         }
       
  1069 
       
  1070         try {
       
  1071             System.out.println(oa1[0]);
       
  1072             Asserts.fail();
       
  1073         } catch (NullPointerException e) {
       
  1074             checkMessage("oa1[0]", e.getMessage(),
       
  1075                                  "while trying to load from a null object array loaded from " +
       
  1076                                  (hasDebugInfo ? "local variable 'oa1'" : "a local variable at slot 9"));
       
  1077         }
       
  1078 
       
  1079         try {
       
  1080             System.out.println(za1[0] = false);
       
  1081             Asserts.fail();
       
  1082         } catch (NullPointerException e) {
       
  1083             checkMessage("za1[0] = false", e.getMessage(),
       
  1084                                  "while trying to store to a null byte (or boolean) array loaded from " +
       
  1085                                  (hasDebugInfo ? "local variable 'za1'" : "a local variable at slot 1"));
       
  1086         }
       
  1087 
       
  1088         try {
       
  1089             System.out.println(ba1[0] = 0);
       
  1090             Asserts.fail();
       
  1091         } catch (NullPointerException e) {
       
  1092             checkMessage("ba1[0] = 0", e.getMessage(),
       
  1093                                  "while trying to store to a null byte (or boolean) array loaded from " +
       
  1094                                  (hasDebugInfo ? "local variable 'ba1'" : "a local variable at slot 2"));
       
  1095         }
       
  1096 
       
  1097         try {
       
  1098             System.out.println(sa1[0] = 0);
       
  1099             Asserts.fail();
       
  1100         } catch (NullPointerException e) {
       
  1101             checkMessage("sa1[0] = 0", e.getMessage(),
       
  1102                                  "while trying to store to a null short array loaded from " +
       
  1103                                  (hasDebugInfo ? "local variable 'sa1'" : "a local variable at slot 3"));
       
  1104         }
       
  1105 
       
  1106         try {
       
  1107             System.out.println(ca1[0] = 0);
       
  1108             Asserts.fail();
       
  1109         } catch (NullPointerException e) {
       
  1110             checkMessage("ca1[0] = 0", e.getMessage(),
       
  1111                                  "while trying to store to a null char array loaded from " +
       
  1112                                  (hasDebugInfo ? "local variable 'ca1'" : "a local variable at slot 4"));
       
  1113         }
       
  1114 
       
  1115         try {
       
  1116             System.out.println(ia1[0] = 0);
       
  1117             Asserts.fail();
       
  1118         } catch (NullPointerException e) {
       
  1119             checkMessage("ia1[0] = 0", e.getMessage(),
       
  1120                                  "while trying to store to a null int array loaded from " +
       
  1121                                  (hasDebugInfo ? "local variable 'ia1'" : "a local variable at slot 5"));
       
  1122         }
       
  1123 
       
  1124         try {
       
  1125             System.out.println(la1[0] = 0);
       
  1126             Asserts.fail();
       
  1127         } catch (NullPointerException e) {
       
  1128             checkMessage("la1[0] = 0", e.getMessage(),
       
  1129                                  "while trying to store to a null long array loaded from " +
       
  1130                                  (hasDebugInfo ? "local variable 'la1'" : "a local variable at slot 6"));
       
  1131         }
       
  1132 
       
  1133         try {
       
  1134             System.out.println(fa1[0] = 0);
       
  1135             Asserts.fail();
       
  1136         } catch (NullPointerException e) {
       
  1137             checkMessage("fa1[0] = 0", e.getMessage(),
       
  1138                                  "while trying to store to a null float array loaded from " +
       
  1139                                  (hasDebugInfo ? "local variable 'fa1'" : "a local variable at slot 7"));
       
  1140         }
       
  1141 
       
  1142         try {
       
  1143             System.out.println(da1[0] = 0);
       
  1144             Asserts.fail();
       
  1145         } catch (NullPointerException e) {
       
  1146             checkMessage("da1[0] = 0", e.getMessage(),
       
  1147                                  "while trying to store to a null double array loaded from " +
       
  1148                                  (hasDebugInfo ? "local variable 'da1'" : "a local variable at slot 8"));
       
  1149         }
       
  1150 
       
  1151         try {
       
  1152             System.out.println(oa1[0] = null);
       
  1153             Asserts.fail();
       
  1154         } catch (NullPointerException e) {
       
  1155             checkMessage("oa1[0] = null", e.getMessage(),
       
  1156                                  "while trying to store to a null object array loaded from " +
       
  1157                                  (hasDebugInfo ? "local variable 'oa1'" : "a local variable at slot 9"));
       
  1158         }
       
  1159 
       
  1160         try {
       
  1161             System.out.println(nullInstanceField.nullInstanceField);
       
  1162             Asserts.fail();
       
  1163         } catch (NullPointerException e) {
       
  1164             checkMessage("nullInstanceField.nullInstanceField", e.getMessage(),
       
  1165                                  "while trying to read the field 'nullInstanceField' of a null object loaded " +
       
  1166                                  "from field 'NullPointerExceptionTest.nullInstanceField' of an object " +
       
  1167                                  "loaded from 'this'");
       
  1168         }
       
  1169 
       
  1170         try {
       
  1171             System.out.println(nullInstanceField.nullInstanceField = null);
       
  1172             Asserts.fail();
       
  1173         } catch (NullPointerException e) {
       
  1174             checkMessage("nullInstanceField.nullInstanceField = null", e.getMessage(),
       
  1175                                  "while trying to write the field 'NullPointerExceptionTest.nullInstanceField' " +
       
  1176                                  "of a null object loaded from field 'NullPointerExceptionTest.nullInstanceField' " +
       
  1177                                  "of an object loaded from 'this'");
       
  1178         }
       
  1179 
       
  1180         try {
       
  1181             System.out.println(za1.length);
       
  1182             Asserts.fail();
       
  1183         } catch (NullPointerException e) {
       
  1184             checkMessage("za1.length", e.getMessage(),
       
  1185                                  "while trying to get the length of a null array loaded from " +
       
  1186                                  (hasDebugInfo ? "local variable 'za1'" : "a local variable at slot 1"));
       
  1187         }
       
  1188 
       
  1189         try {
       
  1190             throw null;
       
  1191         } catch (NullPointerException e) {
       
  1192             checkMessage("throw null", e.getMessage(),
       
  1193                                  "while trying to throw a null exception object loaded " +
       
  1194                                  "from a constant");
       
  1195         }
       
  1196 
       
  1197         try {
       
  1198             synchronized (nullInstanceField) {
       
  1199                 // desired
       
  1200             }
       
  1201         } catch (NullPointerException e) {
       
  1202             checkMessage("synchronized (nullInstanceField)", e.getMessage(),
       
  1203                                  "while trying to enter a null monitor loaded from field " +
       
  1204                                  "'NullPointerExceptionTest.nullInstanceField' of an object loaded from " +
       
  1205                                  "'this'");
       
  1206         }
       
  1207 
       
  1208         try {
       
  1209             nullInstanceField.testCreationViaNew();
       
  1210             Asserts.fail();
       
  1211         } catch (NullPointerException e) {
       
  1212             checkMessage("nullInstanceField.testCreationViaNew()", e.getMessage(),
       
  1213                                  "while trying to invoke the method 'NullPointerExceptionTest.testCreationViaNew()V' on a null reference " +
       
  1214                                  "loaded from field 'NullPointerExceptionTest.nullInstanceField' of an " +
       
  1215                                  "object loaded from 'this'");
       
  1216         }
       
  1217 
       
  1218         try {
       
  1219             nullInstanceField.testNullMessages();
       
  1220             Asserts.fail();
       
  1221         } catch (NullPointerException e) {
       
  1222             checkMessage("nullInstanceField.testNullMessages()", e.getMessage(),
       
  1223                                  "while trying to invoke the method 'NullPointerExceptionTest.testNullMessages()V' on a null reference " +
       
  1224                                  "loaded from field 'NullPointerExceptionTest.nullInstanceField' of an " +
       
  1225                                  "object loaded from 'this'");
       
  1226         }
       
  1227 
       
  1228         try {
       
  1229             // If we can get the value from more than one bci, we cannot know which one.
       
  1230             (Math.random() < 0.5 ? oa1 : (new Object[1])[0]).equals("");
       
  1231         } catch (NullPointerException e) {
       
  1232             checkMessage("(Math.random() < 0.5 ? oa1 : (new Object[1])[0]).equals(\"\")", e.getMessage(),
       
  1233                                  "while trying to invoke the method 'java.lang.Object.equals(Ljava/lang/Object;)Z' on a null reference");
       
  1234         }
  1286         }
  1235     }
  1287     }
  1236 }
  1288 }
       
  1289 
       
  1290 // Helper interface for test cases needed for generateTestClass().
       
  1291 interface E0 {
       
  1292     public int throwNPE(F f);
       
  1293 }
       
  1294 
       
  1295 // Helper class for test cases needed for generateTestClass().
       
  1296 class F {
       
  1297     int i;
       
  1298 }