leibnitz27 / cfr

This is the public repository for the CFR Java decompiler
https://www.benf.org/other/cfr
MIT License
1.94k stars 249 forks source link

Another failing finally example..... #219

Open nitram84 opened 3 years ago

nitram84 commented 3 years ago

CFR version

CFR 0.151-SNAPSHOT (bc71426) and CFR 0.150, so this is not a regression of recent changes

Compiler

openjdk8, openjdk11

Description

Decompiling fails with this exception:

        /*
         * This method has failed to decompile.  When submitting a bug report, please provide this stack trace, and (if you hold appropriate legal rights) the relevant class file.
         * 
         * org.benf.cfr.reader.util.ConfusedCFRException: Tried to end blocks [1[TRYBLOCK]], but top level block is 3[CATCHBLOCK]
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op04StructuredStatement.processEndingBlocks(Op04StructuredStatement.java:435)
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op04StructuredStatement.buildNestedBlocks(Op04StructuredStatement.java:484)
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op03SimpleStatement.createInitialStructuredBlock(Op03SimpleStatement.java:736)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysisInner(CodeAnalyser.java:831)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysisOrWrapFail(CodeAnalyser.java:264)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysis(CodeAnalyser.java:198)
         *     at org.benf.cfr.reader.entities.attributes.AttributeCode.analyse(AttributeCode.java:94)
         *     at org.benf.cfr.reader.entities.Method.analyse(Method.java:531)
         *     at org.benf.cfr.reader.entities.ClassFile.analyseMid(ClassFile.java:1042)
         *     at org.benf.cfr.reader.entities.ClassFile.analyseTop(ClassFile.java:929)
         *     at org.benf.cfr.reader.Driver.doJarVersionTypes(Driver.java:257)
         *     at org.benf.cfr.reader.Driver.doJar(Driver.java:139)
         *     at org.benf.cfr.reader.CfrDriverImpl.analyse(CfrDriverImpl.java:73)
         *     at org.benf.cfr.reader.Main.main(Main.java:49)
         */

Example

public class CfrTestConfusedCFRException {

    public void run() throws InterruptedException {
        try {
            doSomethingCanThrowExceptions();
        } catch (InterruptedException ex) {
            throw ex;
        } catch (Exception ex) {
            doSomething();
        } finally {
            System.out.println(String.format("%s", "abcd"));
        }
    }

    private void doSomething() {
    }

    // minimized, but assume method could throw any exception 
    private void doSomethingCanThrowExceptions() throws Exception {
    }
}

This example can be used for the cfr test suite.

leibnitz27 commented 3 years ago

Thanks - it's less the try/catch than the finally..... finally's actually quite a pain. :(