Uploaded image for project: 'SonarJava'
  1. SonarJava
  2. SONARJAVA-2737

CFG: exceptions should bubble up to the next enclosing try

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: CFG
    • Labels:
      None

      Description

      import java.io.IOException;
      import java.net.ServerSocket;
      import java.util.logging.Logger;
      
      public class FreePort {
      
          private FreePort() {
          }
      
          public static void main(String[] args) {
              if(available()) { // <= issue reported here S2589
                  Logger.getAnonymousLogger().info("available");
              }
          }
      
          private static boolean available() {
              try {
                  try (ServerSocket ss = new ServerSocket(4200)) {
                      ss.setReuseAddress(true); // Throws SocketException which is subtype of IOException and should be linked to catch of outer try.
                  }
                  return true;
              } catch (IOException e) {
                  return false;
              }
          }
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                nicolas.peru Nicolas Peru
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: