Created
March 28, 2012 02:03
-
-
Save hideaki-t/2222849 to your computer and use it in GitHub Desktop.
possible resource leak in try-with-resources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
public class Main { | |
public static void main(String[] args) { | |
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("hoge")))) { | |
// use buffered reader ... | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(java.lang.String[]); | |
Code: | |
0: new #2 // class java/io/BufferedReader | |
3: dup | |
4: new #3 // class java/io/InputStreamReader | |
7: dup | |
8: new #4 // class java/io/FileInputStream | |
11: dup | |
12: ldc #5 // String hoge | |
14: invokespecial #6 // Method java/io/FileInputStream."<init>":(Ljava/lang/String;)V | |
17: invokespecial #7 // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;)V | |
20: invokespecial #8 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;)V | |
23: astore_1 | |
24: aconst_null | |
25: astore_2 | |
26: aload_1 | |
27: ifnull 92 | |
30: aload_2 | |
31: ifnull 50 | |
34: aload_1 | |
35: invokevirtual #9 // Method java/io/BufferedReader.close:()V | |
38: goto 92 | |
41: astore_3 | |
42: aload_2 | |
43: aload_3 | |
44: invokevirtual #11 // Method java/lang/Throwable.addSuppressed:(Ljava/lang/Throwable;)V | |
47: goto 92 | |
50: aload_1 | |
51: invokevirtual #9 // Method java/io/BufferedReader.close:()V | |
54: goto 92 | |
57: astore 4 | |
59: aload_1 | |
60: ifnull 89 | |
63: aload_2 | |
64: ifnull 85 | |
67: aload_1 | |
68: invokevirtual #9 // Method java/io/BufferedReader.close:()V | |
71: goto 89 | |
74: astore 5 | |
76: aload_2 | |
77: aload 5 | |
79: invokevirtual #11 // Method java/lang/Throwable.addSuppressed:(Ljava/lang/Throwable;)V | |
82: goto 89 | |
85: aload_1 | |
86: invokevirtual #9 // Method java/io/BufferedReader.close:()V | |
89: aload 4 | |
91: athrow | |
92: goto 100 | |
95: astore_1 | |
96: aload_1 | |
97: invokevirtual #13 // Method java/io/IOException.printStackTrace:()V | |
100: return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
public class Main { | |
public static void main(String[] args) { | |
try (FileInputStream fis = new FileInputStream("hoge"); | |
InputStreamReader isr = new InputStreamReader(fis); | |
BufferedReader br = new BufferedReader(isr) | |
) { | |
// use buffered reader ... | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(java.lang.String[]); | |
Code: | |
0: new #2 // class java/io/FileInputStream | |
3: dup | |
4: ldc #3 // String hoge | |
6: invokespecial #4 // Method java/io/FileInputStream."<init>":(Ljava/lang/String;)V | |
9: astore_1 | |
10: aconst_null | |
11: astore_2 | |
12: new #5 // class java/io/InputStreamReader | |
15: dup | |
16: aload_1 | |
17: invokespecial #6 // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;)V | |
20: astore_3 | |
21: aconst_null | |
22: astore 4 | |
24: new #7 // class java/io/BufferedReader | |
27: dup | |
28: aload_3 | |
29: invokespecial #8 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;)V | |
32: astore 5 | |
34: aconst_null | |
35: astore 6 | |
37: aload 5 | |
39: ifnull 115 | |
42: aload 6 | |
44: ifnull 67 | |
47: aload 5 | |
49: invokevirtual #9 // Method java/io/BufferedReader.close:()V | |
52: goto 115 | |
55: astore 7 | |
57: aload 6 | |
59: aload 7 | |
61: invokevirtual #11 // Method java/lang/Throwable.addSuppressed:(Ljava/lang/Throwable;)V | |
64: goto 115 | |
67: aload 5 | |
69: invokevirtual #9 // Method java/io/BufferedReader.close:()V | |
72: goto 115 | |
75: astore 8 | |
77: aload 5 | |
79: ifnull 112 | |
82: aload 6 | |
84: ifnull 107 | |
87: aload 5 | |
89: invokevirtual #9 // Method java/io/BufferedReader.close:()V | |
92: goto 112 | |
95: astore 9 | |
97: aload 6 | |
99: aload 9 | |
101: invokevirtual #11 // Method java/lang/Throwable.addSuppressed:(Ljava/lang/Throwable;)V | |
104: goto 112 | |
107: aload 5 | |
109: invokevirtual #9 // Method java/io/BufferedReader.close:()V | |
112: aload 8 | |
114: athrow | |
115: aload_3 | |
116: ifnull 196 | |
119: aload 4 | |
121: ifnull 143 | |
124: aload_3 | |
125: invokevirtual #12 // Method java/io/InputStreamReader.close:()V | |
128: goto 196 | |
131: astore 5 | |
133: aload 4 | |
135: aload 5 | |
137: invokevirtual #11 // Method java/lang/Throwable.addSuppressed:(Ljava/lang/Throwable;)V | |
140: goto 196 | |
143: aload_3 | |
144: invokevirtual #12 // Method java/io/InputStreamReader.close:()V | |
147: goto 196 | |
150: astore 5 | |
152: aload 5 | |
154: astore 4 | |
156: aload 5 | |
158: athrow | |
159: astore 10 | |
161: aload_3 | |
162: ifnull 193 | |
165: aload 4 | |
167: ifnull 189 | |
170: aload_3 | |
171: invokevirtual #12 // Method java/io/InputStreamReader.close:()V | |
174: goto 193 | |
177: astore 11 | |
179: aload 4 | |
181: aload 11 | |
183: invokevirtual #11 // Method java/lang/Throwable.addSuppressed:(Ljava/lang/Throwable;)V | |
186: goto 193 | |
189: aload_3 | |
190: invokevirtual #12 // Method java/io/InputStreamReader.close:()V | |
193: aload 10 | |
195: athrow | |
196: aload_1 | |
197: ifnull 267 | |
200: aload_2 | |
201: ifnull 220 | |
204: aload_1 | |
205: invokevirtual #13 // Method java/io/FileInputStream.close:()V | |
208: goto 267 | |
211: astore_3 | |
212: aload_2 | |
213: aload_3 | |
214: invokevirtual #11 // Method java/lang/Throwable.addSuppressed:(Ljava/lang/Throwable;)V | |
217: goto 267 | |
220: aload_1 | |
221: invokevirtual #13 // Method java/io/FileInputStream.close:()V | |
224: goto 267 | |
227: astore_3 | |
228: aload_3 | |
229: astore_2 | |
230: aload_3 | |
231: athrow | |
232: astore 12 | |
234: aload_1 | |
235: ifnull 264 | |
238: aload_2 | |
239: ifnull 260 | |
242: aload_1 | |
243: invokevirtual #13 // Method java/io/FileInputStream.close:()V | |
246: goto 264 | |
249: astore 13 | |
251: aload_2 | |
252: aload 13 | |
254: invokevirtual #11 // Method java/lang/Throwable.addSuppressed:(Ljava/lang/Throwable;)V | |
257: goto 264 | |
260: aload_1 | |
261: invokevirtual #13 // Method java/io/FileInputStream.close:()V | |
264: aload 12 | |
266: athrow | |
267: goto 275 | |
270: astore_1 | |
271: aload_1 | |
272: invokevirtual #15 // Method java/io/IOException.printStackTrace:()V | |
275: return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment