javacypherjqassistant

Find checked/unchecked Exceptions with jQAssistant


I'm trying to use jqassistant to find any checked exceptions used in my project. Is there any way to differentiate between checked/unchecked exceptions with jqa?


Solution

  • It's possible to detect usage of checked exceptions if you know which types are checked exceptions, i.e. inherit from java.lang.Exception.

    The problem here is that you will probably not see the full inheritance hierarchy as this requires all involved artifacts to be scanned. As an example you will see that any of your application's exceptions inherits from java.io.IOException but as the JRE-JAR file has not been scanned it is not visible in the graph that this exception actually extends java.lang.Exception. This limitation also holds for all other used libraries that might provide their own exception types.

    A way to get around this is to explicitly mark required exception types with labels :Exception and :Checked, e.g.

    MATCH
      (:Artifact)-[:REQUIRES]->(e:Type)
    WHERE
      e.fqn in [
        "java.lang.Exception",
        "java.io.IOException"
      ]
    SET
      e:Exception:Checked
    RETURN
      e
    

    Using this concept it is possible to create a report about methods that create instances of checked exceptions:

    MATCH
      (t:Type)-[:DECLARES]->(m:Method)-[i:INVOKES]->(:Constructor)<-[:DECLARES]-(e:Exception:Checked)
    RETURN
      t.fqn, m.signature, i.lineNumber