Loosen checking of unreachable suppressed exceptions in try-with-resources
    Nikita An. Sokolov 
    faucct at yandex-team.ru
       
    Thu Oct  7 10:18:25 UTC 2021
    
    
  
(jep-submit at openjdk.java.net <mailto:jep-submit at openjdk.java.net> is unknown, so I am sending this proposal here)
Summary
-------
Do not require to catch checked exceptions from closed resources when they are being suppressed by an unconditional throw inside try-block body.
Success Metrics
---------------
Method fileInputStream should compile and not require to handle IOException from closing fileInputStream, as it will always be suppressed by rethrown RuntimeException:
```
FileInputStream fileInputStream(File file) throws FileNotFoundException {
  final var fileInputStream = new FileInputStream(file);
  try {
      checkSomething();
  } catch (Exception e) {
      try (fileInputStream) {
          throw e;
      }
  }
  return fileInputStream;
}
void checkSomething() {
  throw new RuntimeException();
}
```
Motivation
----------
This would let skipping unreachable catch sections.
Description
-----------
I guess this would only require changes in Java compiler.
Risks and Assumptions
---------------------
This change might require to delete unreachable catch blocks in some existing code. To smooth this change such blocks may be allowed, maybe producing a warning.
    
    
More information about the amber-dev
mailing list