Q:

compiled class problem in java try/catch block

I have try and catch block in JAVA code
import java.io.FileOutputStream;
import java.util.zip.ZipOutputStream;

public class TryTest {

    public static void main(String[] args) {
        String zipPath ="D:/test";
        try (ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipPath))){
            String Hello ="Hello";
            System.out.println("==============>"+Hello);
        }catch (Exception e) {
            e.printStackTrace();
        }

    }

}

And my compiled class look like 
/*
 * Decompiled with CFR 0.145.
 */
....
try {
    try (ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(string));){
        String string2 = "Hello";
        System.out.println("==============>" + string2);
    }

....
I wounder why another try block added in compile time.
Full Source code in 
https://github.com/vikram06/java_try_catch_bug

A:

This is explained in the JLS 14.20.3.2 Extended try-with-resources :

The meaning of an extended try-with-resources statement:

try ResourceSpecification
    Block
Catchesopt
Finallyopt

is given by the following translation to a basic try-with-resources
  statement (§14.20.3.1) nested inside a try-catch or try-finally or
  try-catch-finally statement:

try {
    try ResourceSpecification
        Block
}
Catchesopt
Finallyopt

The effect of the translation is to put the ResourceSpecification
  "inside" the try statement. This allows a catch clause of an extended
  try-with-resources statement to catch an exception due to the
  automatic initialization or closing of any resource.
Furthermore, all resources will have been closed (or attempted to be
  closed) by the time the finally block is executed, in keeping with the
  intent of the finally keyword.

A:

When you're using try with resources (I mean try (...) {... ) then Java compiler generates additional code section to display the stacktrace from local variable of type Throwable. That's because Java compiler is decomposing try with resources statement into separate tries - one for closing the resource and another for statements inside your try.
How is it displayed after decompilation - it depends on the decompiler you use.

