|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
23 | 23 |
|
24 | 24 | /*
|
25 | 25 | * @test
|
26 |
| - * @bug 8022186 |
| 26 | + * @bug 8022186 8271254 |
27 | 27 | * @summary javac generates dead code if a try with an empty body has a finalizer
|
28 | 28 | * @modules jdk.jdeps/com.sun.tools.classfile
|
29 | 29 | * jdk.compiler/com.sun.tools.javac.util
|
@@ -53,15 +53,18 @@ public static void main(String[] args) throws Exception {
|
53 | 53 | }
|
54 | 54 |
|
55 | 55 | void run() throws Exception {
|
56 |
| - checkClassFile(Paths.get(System.getProperty("test.classes"), |
57 |
| - this.getClass().getName() + "$Test.class")); |
| 56 | + for (int i = 1; i <= 8; i++) { |
| 57 | + checkClassFile(Paths.get(System.getProperty("test.classes"), |
| 58 | + this.getClass().getName() + "$Test" + i + ".class")); |
| 59 | + } |
58 | 60 | }
|
59 | 61 |
|
60 | 62 | int utf8Index;
|
61 | 63 | int numberOfRefToStr = 0;
|
62 | 64 | ConstantPool constantPool;
|
63 | 65 |
|
64 | 66 | void checkClassFile(final Path path) throws Exception {
|
| 67 | + numberOfRefToStr = 0; |
65 | 68 | ClassFile classFile = ClassFile.read(
|
66 | 69 | new BufferedInputStream(Files.newInputStream(path)));
|
67 | 70 | constantPool = classFile.constant_pool;
|
@@ -155,9 +158,92 @@ public Void visitUnknown(Instruction instr, Void p) {
|
155 | 158 |
|
156 | 159 | }
|
157 | 160 |
|
158 |
| - public class Test { |
| 161 | + public class Test1 { |
| 162 | + void methodToLookFor() { |
| 163 | + try { |
| 164 | + // empty intentionally |
| 165 | + } finally { |
| 166 | + System.out.println("STR_TO_LOOK_FOR"); |
| 167 | + } |
| 168 | + } |
| 169 | + } |
| 170 | + |
| 171 | + public class Test2 { |
| 172 | + void methodToLookFor() { |
| 173 | + try { |
| 174 | + // empty intentionally |
| 175 | + } catch (Exception e) { |
| 176 | + System.out.println("EXCEPTION"); |
| 177 | + } finally { |
| 178 | + System.out.println("STR_TO_LOOK_FOR"); |
| 179 | + } |
| 180 | + } |
| 181 | + } |
| 182 | + |
| 183 | + public class Test3 { |
| 184 | + void methodToLookFor() { |
| 185 | + try { |
| 186 | + ; // skip statement intentionally |
| 187 | + } finally { |
| 188 | + System.out.println("STR_TO_LOOK_FOR"); |
| 189 | + } |
| 190 | + } |
| 191 | + } |
| 192 | + |
| 193 | + public class Test4 { |
| 194 | + void methodToLookFor() { |
| 195 | + try { |
| 196 | + ; // skip statement intentionally |
| 197 | + } catch (Exception e) { |
| 198 | + System.out.println("EXCEPTION"); |
| 199 | + } finally { |
| 200 | + System.out.println("STR_TO_LOOK_FOR"); |
| 201 | + } |
| 202 | + } |
| 203 | + } |
| 204 | + |
| 205 | + public class Test5 { |
| 206 | + void methodToLookFor() { |
| 207 | + try { |
| 208 | + // empty try statement |
| 209 | + try { } finally { } |
| 210 | + } finally { |
| 211 | + System.out.println("STR_TO_LOOK_FOR"); |
| 212 | + } |
| 213 | + } |
| 214 | + } |
| 215 | + |
| 216 | + public class Test6 { |
| 217 | + void methodToLookFor() { |
| 218 | + try { |
| 219 | + // empty try statement |
| 220 | + try { } catch (Exception e) { } finally { } |
| 221 | + } catch (Exception e) { |
| 222 | + System.out.println("EXCEPTION"); |
| 223 | + } finally { |
| 224 | + System.out.println("STR_TO_LOOK_FOR"); |
| 225 | + } |
| 226 | + } |
| 227 | + } |
| 228 | + |
| 229 | + public class Test7 { |
| 230 | + void methodToLookFor() { |
| 231 | + try { |
| 232 | + // empty try statement with skip statement |
| 233 | + try { ; } finally { } |
| 234 | + } finally { |
| 235 | + System.out.println("STR_TO_LOOK_FOR"); |
| 236 | + } |
| 237 | + } |
| 238 | + } |
| 239 | + |
| 240 | + public class Test8 { |
159 | 241 | void methodToLookFor() {
|
160 | 242 | try {
|
| 243 | + // empty try statement with skip statement |
| 244 | + try { ; } catch (Exception e) { } finally { } |
| 245 | + } catch (Exception e) { |
| 246 | + System.out.println("EXCEPTION"); |
161 | 247 | } finally {
|
162 | 248 | System.out.println("STR_TO_LOOK_FOR");
|
163 | 249 | }
|
|
0 commit comments