Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

weird behavior of the Quick Fix; "Surround with try/catch" #2711

Closed
arithauth opened this issue Oct 2, 2022 · 8 comments
Closed

weird behavior of the Quick Fix; "Surround with try/catch" #2711

arithauth opened this issue Oct 2, 2022 · 8 comments
Assignees

Comments

@arithauth
Copy link

arithauth commented Oct 2, 2022

[weird behavior of auto generate when generating try-catch]

Environment
  • Operating System: macOS 12.6(Monterey)
  • JDK version: java(TM) SE Runtime Environment (build 18.0.2.1+1-1)
  • Visual Studio Code version: 1.71.2 (Universal)
  • Java extension version: v1.11.0
Steps To Reproduce
<-- insert
try {

} catch (Exception e) {
    // TODO: handle exception
}
throw new Exception(); <-- use Quick Fix; "Surround with try/catch"
try {

} catch (Exception e) {
    // TODO: handle exception
}
try {
    throw new Exception(); <-- surrounded by Quick Fix
} catch (Exception e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
}
try {

} catch (Exception e) {
    // TODO: handle exception
}
Current Result

Even if this variable name "e1" were "e", it won't conflict any other variables.

Expected Result

Maybe (Exception e) is correct behavior.

Additional Informations
@arithauth arithauth changed the title weird behavior of auto generate when generating try-catch weird behavior of the Quick Fix; "Surround with try/catch" Oct 5, 2022
@rgrunber
Copy link
Member

I'm able to reproduce as well. In fact, this is basically the same as https://bugs.eclipse.org/bugs/show_bug.cgi?id=36365 (which was fixed long ago), but if one applies the refactoring from the bottom-up it's still reproducible.

@arithauth
Copy link
Author

Thank you.
That the fact is interesting. If new Exception() is inside a scope, using Quick Fix above the existing try-catch does not make this behavior.
Well, should I post this to eclipse bug report?

@rgrunber
Copy link
Member

rgrunber commented Nov 1, 2022

https://github.com/eclipse-jdt/eclipse.jdt.ui would be the place. Unfortunately it's not possible to transfer this issue from here to there although that probably would have been ideal. I mentioned the issue to @jjohnstn, who is also a committer there so there is some awareness of it.

@arithauth
Copy link
Author

I will wait for it to be fixed. I appreciate it.

@jjohnstn
Copy link

The following issue has been opened: eclipse-jdt/eclipse.jdt.ui#353

@jjohnstn
Copy link

Fix has been merged but the change for try/catch is in JDT UI and will need to either be refactored or copied for jdt-ls. The problem also existed for surround with try-with-resources and has been fixed as well. No refactoring needed for the second fix.

@rgrunber rgrunber added this to the Early January 2023 milestone Dec 21, 2022
@rgrunber rgrunber self-assigned this Dec 21, 2022
@rgrunber
Copy link
Member

I can have a look at what needs to be copied and adjust it.

rgrunber added a commit to rgrunber/eclipse.jdt.ls that referenced this issue Dec 22, 2022
rgrunber added a commit to rgrunber/eclipse.jdt.ls that referenced this issue Dec 31, 2022
rgrunber added a commit to eclipse-jdtls/eclipse.jdt.ls that referenced this issue Dec 31, 2022
@arithauth
Copy link
Author

I found that it have been fixed. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

3 participants