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

"final" modifier not added to exception multi-catch block variable #3075

Closed
lbrayner opened this issue Feb 27, 2024 · 5 comments
Closed

"final" modifier not added to exception multi-catch block variable #3075

lbrayner opened this issue Feb 27, 2024 · 5 comments
Labels

Comments

@lbrayner
Copy link
Contributor

Consider the following code:

public class FinalExceptions {

  public static void main(String[] args) {
    Object token = new Object();

    try {
      token.wait();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    try {
      token.wait();
    } catch (IllegalMonitorStateException | InterruptedException e) {
      e.printStackTrace();
    }
  }
}

If you request code action "Change modifiers to final where possible", final is only added to the first catch form, even though final could be added to the multi-catch form too.

@snjeza
Copy link
Contributor

snjeza commented Feb 28, 2024

This is an upstream jdt issue. I can reproduce it in Eclipse.
@lbrayner Could you create an issue at https://github.com/eclipse-jdt/eclipse.jdt.ui/issues

@lbrayner
Copy link
Contributor Author

This is an upstream jdt issue. I can reproduce it in Eclipse. @lbrayner Could you create an issue at https://github.com/eclipse-jdt/eclipse.jdt.ui/issues

@snjeza sure, I should have tried that, it seemed like an upstream thing.

@lbrayner
Copy link
Contributor Author

@snjeza how do I reproduce this in Eclipse? Didn't find any refactor or source actions for this.

@snjeza
Copy link
Contributor

snjeza commented Feb 29, 2024

@lbrayner Right click in the editor, select Source>Clean Up...
You have to define your profile with

  • Add final modifier to private fields
  • Add final modifier to method parameters
  • Add final modifier to local variables
    final

@lbrayner
Copy link
Contributor Author

lbrayner commented Mar 4, 2024

@snjeza sorry, my silly mistake: The parameter e of a multi-catch block cannot be assigned. Final is useless there. Closing this. But thanks a lot for your help!

@lbrayner lbrayner closed this as completed Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants