5

发现一个神奇的现象, idea 无法反编译 catch 块中带 return 的 groovy 代码

 3 years ago
source link: https://www.v2ex.com/t/787276
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  程序员

发现一个神奇的现象, idea 无法反编译 catch 块中带 return 的 groovy 代码

  git00ll · 1 天前 · 688 次点击

catch 代码块中含有 return,会导致 idea 反编译不出来

如果代码是这样的

@CompileStatic
class TestGroovy {

    void funcA() {
        try {
            def a = 1 + 1
        } catch (e) {
            println e
        }
    }
}

idea 反编译结果

    public void funcA() {
        try {
            try {
                int a = 1 + 1;
            } catch (Exception var6) {
                DefaultGroovyMethods.println(this, var6);
                Object var10000 = null;
            }

        } finally {
            ;
        }
    }

上面没问题,大概能根据反编译的代码看出原始代码。

如果在 catch 块中添加 return 语句

@CompileStatic
class TestGroovy {

    void funcA() {
        try {
            def a = 1 + 1
        } catch (e) {
            println e
            return
        }
    }
}

idea 反编译无法反编译

    public void funcA() {
        // $FF: Couldn't be decompiled
    }

使用 jd.gui 进行反编译,能正常反编译,而且变量名更友好。

  public void funcA() {
    try {
      int a = 1 + 1;
    } catch (Exception e) {
      DefaultGroovyMethods.println(this, e);
      null;
      return;
    } finally {}
  }

idea 2019.03

所以如何能让 idea 的反编译达到 jd.gui 这种效果呢


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK