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

refine exception type of try-catch edges #134

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

d367wang
Copy link

@d367wang d367wang commented May 31, 2020

This PR refines the type of exception for try-catch edges, which is shown as the label of each exceptional edge in CFG. The refinement is divided into two cases: (i) If thrown type is a subtype of caught type, then the edge is labeled the type of thrown type; (ii) If thrown type is a supertype of caught type, then the edge is labeled the type of caught type.

@wmdietl
Copy link
Member

wmdietl commented May 31, 2020

Previous PR #131.
Is there a reason you didn't continue with that PR?

@d367wang
Copy link
Author

I rollback the code to the origin/master because in PR #131 , there is marker text-related modification that makes the PR not single-purposed, and then push to the remote repository so that the PR is closed automatically.

@d367wang d367wang requested a review from wmdietl June 3, 2020 20:50
@wmdietl wmdietl self-assigned this Jun 4, 2020
@wmdietl
Copy link
Member

wmdietl commented Jun 22, 2020

@xingweitian Can you have a look at this PR?

@wmdietl wmdietl assigned xingweitian and unassigned wmdietl Jun 22, 2020
@mernst
Copy link

mernst commented Jun 22, 2020

@msridhar

@wmdietl
Copy link
Member

wmdietl commented Jun 22, 2020

@d367wang I talked with @mernst about this PR today. He noted that instead of using Throwable it might be better to use RuntimeException | Error as label.
I think @msridhar wanted the same - please comment if you needed something else.

@msridhar
Copy link

We were looking at the case of an expression new Foo() outside any try-catch. If the Foo() constructor does not have an explicit throws declaration, there is an exceptional edge from the new Foo() expression to the exceptional exit with associated type java.lang.Throwable. This would be useful to refine into RuntimeException | Error, since without that refinement one cannot distinguish the case of having no throws declaration from the case Foo() throws Throwable.

When Foo() does have a throws declaration, like Foo() throws IOException, we see two exceptional edges from new Foo(), once with type Throwable and one with type IOException. So we can currently distinguish edges due to throws declarations from the catch-all Throwable case, except for throws Throwable. This maybe seems like a corner case, but if it can be easily handled in this PR, it may be worthwhile.

/cc @Nargeshdb

Copy link

@xingweitian xingweitian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Here are some of my initial thinking:


if (caught instanceof DeclaredType) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between caught instanceof DeclaredType and caught.getKind() == TypeKind.DECLARED?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A union-type exception, like IOException | NullPointerException is DeclaredType. As a result, a catch block parameterized with a union-type exception will also fall into the if-branch.

if (canApply) {
labels.add(pair.second);
} else {
assert false : "caught type must be a union or a declared type";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to write throw new BugInCF("Caught type must be a union or a declared type."); here.

// Add Throwable to account for unchecked exceptions
TypeElement throwableElement = elements.getTypeElement("java.lang.Throwable");
thrownSet.add(throwableElement.asType());
//

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line.

* Given a type of thrown exception, add the set of possible control flow successor {@link
* Label}s to the argument set. Return true if the exception is known to be caught by one of
* those labels and false if it may propagate still further.
* Given a type of thrown exception, add to the argument set all possible pairs of the

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -401,18 +401,21 @@ public String toString() {
protected final Node node;

/**
* Map from exception type to labels of successors that may be reached as a result of that
* exception.
* Set of all possible pairs of the refined exception type {@link TypeMirror} and the

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pairs of the refined exception types and the corresponding targets' labels?
Maybe remove {@link Label}? or change label to {@link Label}s.


/**
* Construct a NodeWithExceptionsHolder for the given node and exceptions.
*
* @param node the node to hold
* @param exceptions the exceptions to hold
* @param exceptions set of all possible pairs of the refined exception type {@link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. Please have a look at all the appears.

* <p>Return true if the exception is known to be caught by one of those labels and false if
* it may propagate still further.
*
* @param thrown the type of the exception that is declared to be thrown from a method

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove . at the end of the line. @param and @return should not write . at the end of the line. Please change all the usages in this PR.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* invocation, waiting to be refined.
* @param causeLabelPairs the set of all possible pairs of the refined exception type {@link
* TypeMirror} and the corresponding target's label {@link Label} that may be reached as
* a result of {@code thrown}.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A result of the current exception node?

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

Successfully merging this pull request may close these issues.

5 participants