test/langtools/jdk/jshell/ExceptionsTest.java
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 49515 083318155ad1
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
     1 /*
     1 /*
     2  * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    22  */
    22  */
    23 
    23 
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @summary Tests for exceptions
    26  * @summary Tests for exceptions
    27  * @bug 8198801
    27  * @bug 8198801 8212167
    28  * @build KullaTesting TestingInputStream
    28  * @build KullaTesting TestingInputStream
    29  * @run testng ExceptionsTest
    29  * @run testng ExceptionsTest
    30  */
    30  */
    31 
    31 
    32 import java.io.IOException;
    32 import java.io.IOException;
   205                         newStackTraceElement("1A", "f", s1, 4),
   205                         newStackTraceElement("1A", "f", s1, 4),
   206                         newStackTraceElement("", "f", s1, 7),
   206                         newStackTraceElement("", "f", s1, 7),
   207                         newStackTraceElement("", "", cr2.snippet(), 1)));
   207                         newStackTraceElement("", "", cr2.snippet(), 1)));
   208     }
   208     }
   209 
   209 
       
   210     // test 8212167
       
   211     public void throwLineFormat1() {
       
   212         SnippetEvent se = assertEvalException(
       
   213                 "if (true) { \n" +
       
   214                         "   int x = 10; \n" +
       
   215                         "   int y = 10 / 0;}"
       
   216         );
       
   217         assertExceptionMatch(se,
       
   218                 new ExceptionInfo(ArithmeticException.class, "/ by zero",
       
   219                         newStackTraceElement("", "", se.snippet(), 3)));
       
   220     }
       
   221 
       
   222     public void throwLineFormat3() {
       
   223         Snippet sp = methodKey(assertEval(
       
   224                 "int p() \n" +
       
   225                         "  { return 4/0; }"));
       
   226         Snippet sm = methodKey(assertEval(
       
   227                 "int m(int x)\n" +
       
   228                         "       \n" +
       
   229                         "       {\n" +
       
   230                         "          return p() + x; \n" +
       
   231                         "       }"));
       
   232         Snippet sn = methodKey(assertEval(
       
   233                 "int n(int x) {\n" +
       
   234                         "         try {\n" +
       
   235                         "           return m(x);\n" +
       
   236                         "         }\n" +
       
   237                         "         catch (Throwable ex) {\n" +
       
   238                         "           throw new IllegalArgumentException( \"GOT:\", ex);\n" +
       
   239                         "         }\n" +
       
   240                         "       }"));
       
   241         SnippetEvent se = assertEvalException("n(33);");
       
   242         assertExceptionMatch(se,
       
   243                 new ExceptionInfo(IllegalArgumentException.class, null,
       
   244                         new ExceptionInfo(ArithmeticException.class, "/ by zero",
       
   245                                 newStackTraceElement("", "p", sp, 2),
       
   246                                 newStackTraceElement("", "m", sm, 4),
       
   247                                 newStackTraceElement("", "n", sn, 3),
       
   248                                 newStackTraceElement("", "", se.snippet(), 1)),
       
   249                         newStackTraceElement("", "n", sn, 6),
       
   250                         newStackTraceElement("", "", se.snippet(), 1)));
       
   251     }
       
   252 
   210     @Test(enabled = false) // TODO 8129427
   253     @Test(enabled = false) // TODO 8129427
   211     public void outOfMemory() {
   254     public void outOfMemory() {
   212         assertEval("import java.util.*;");
   255         assertEval("import java.util.*;");
   213         assertEval("List<byte[]> list = new ArrayList<>();");
   256         assertEval("List<byte[]> list = new ArrayList<>();");
   214         assertExecuteException("while (true) { list.add(new byte[10000]); }", OutOfMemoryError.class);
   257         assertExecuteException("while (true) { list.add(new byte[10000]); }", OutOfMemoryError.class);
   330                         assertTrue(actualElement.getMethodName().startsWith("lambda$"), message + " : method names");
   373                         assertTrue(actualElement.getMethodName().startsWith("lambda$"), message + " : method names");
   331                     } else {
   374                     } else {
   332                         assertEquals(actualElement.getMethodName(), expectedElement.getMethodName(), message + " : method names");
   375                         assertEquals(actualElement.getMethodName(), expectedElement.getMethodName(), message + " : method names");
   333                     }
   376                     }
   334                     assertEquals(actualElement.getFileName(), expectedElement.getFileName(), message + " : file names");
   377                     assertEquals(actualElement.getFileName(), expectedElement.getFileName(), message + " : file names");
   335                     assertEquals(actualElement.getLineNumber(), expectedElement.getLineNumber(), message + " : line numbers");
   378                     assertEquals(actualElement.getLineNumber(), expectedElement.getLineNumber(), message + " : line numbers"
       
   379                         + " -- actual: " + actualElement.getLineNumber() + ", expected: " + expectedElement.getLineNumber() +
       
   380                             " -- in: " + actualElement.getClassName());
   336                 }
   381                 }
   337             }
   382             }
   338         }
   383         }
   339     }
   384     }
   340 
   385