java-decompiler / jd-gui

A standalone Java Decompiler GUI
GNU General Public License v3.0
14.09k stars 2.4k forks source link

Matching class names generate incorrect source #434

Open albfan opened 1 year ago

albfan commented 1 year ago

for two classes with same name and different package:

bar.MyException;
foo.MyException;

A class using them:

public class Test {
    public static void main(String[] args) {
        boolean flag = true;
        try {
            if(flag) {
                throw new foo.MyException();
            } else {
                throw new bar.MyException();
            }
        } catch (foo.MyException e) {

        } catch (bar.MyException ex) {

        }
    }
}

is decomplied as:

import bar.MyException;
import foo.MyException;

public class Test {
  public static void main(String[] args) {
    boolean flag = true;
    try {
      if (flag)
        throw new MyException(); 
      throw new MyException();
    } catch (MyException myException) {

    } catch (MyException myException) {}
  }
}

Is it possible to detect this name match and explicity put which class is used in which place?

I can provide the maven project to test if needed