-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Enable Error Prone check: CheckedExceptionNotThrown #8227
Enable Error Prone check: CheckedExceptionNotThrown #8227
Conversation
@@ -40,7 +40,6 @@ public LazyConnectionFactory(@ForLazyConnectionFactory ConnectionFactory delegat | |||
|
|||
@Override | |||
public Connection openConnection(ConnectorSession session) | |||
throws SQLException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping this helps update the code in the future, would i want to throw a checked exception (as super/interface allows me to)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you only call this method via the interface, you should be safe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i mean a future self who will be changing the implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then your future self will add this exception back? It doesn't affect the interface, or its callers, only the override.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, except
- except the method is not allowed to throw a checked exception (i need to consult parent for that, which i may not do), so i may e.g. wrap IOException in Runtime unnecessarily and reviewer may miss that either
- someone can call the impl directly (not via interface), so such legit reintroduction of a checked exception may still be a breaking change for callers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we suppress it here, as other cases where throws
is removed seem valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppressed the error in this method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this considered an errorprone bug and reported upstream?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm personally still on the fence on this. On the one hand I'd love it to lead to removal of dead code more (if none of the implementations throw this, we can remove the throws
from the interface declaration!), but on the other I guess you're right that it's better to be conservative here.
I can create an issue upstream to see what they think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1cde497
to
200412a
Compare
Refreshing this old PR. It looks like this check is getting more precise (and thus useful), though it still misses lots of cases. |
testing/trino-testing/src/main/java/io/trino/testing/AbstractTestQueryFramework.java
Outdated
Show resolved
Hide resolved
200412a
to
3764d0f
Compare
Weird:
|
3764d0f
to
ee022be
Compare
The Pinot failure is #13165. For Redis:
Looks like a hiccup in the environment. There are some code changes in the PR, but they should not affect any tests anyway. |
Re started failed jobs. Please report flaky failures as github issues. |
The build is green, thanks. Not sure if there's anything to report if it was some instability in the build infra? |
@@ -39,6 +39,7 @@ public LazyConnectionFactory(@ForLazyConnectionFactory ConnectionFactory delegat | |||
} | |||
|
|||
@Override | |||
@SuppressWarnings("CheckedExceptionNotThrown") // throws in the interface declaration; keep it to prevent false sense of security |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't understand the comment message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW this seems not violate the check
public interface AnInterface
{
void foo()
throws Exception;
}
public class AnImplementationThatCurrentlyDoesNotThrow
implements AnInterface
{
@Override
public void foo()
throws Exception
{}
}
so why do we need suppression here?
is it a bug in error-prone?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's difficult to tell why it's not reported. Maybe there's an exception for Exception
(but there are some places where it reports Exception
, so likely not). I don't know what logic it uses to find those cases, but I'm pretty sure it doesn't find everything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out that this check does trigger in this case if the class is final
, otherwise it does not. See this comment: google/error-prone#3425 (comment)
@@ -52,13 +52,11 @@ | |||
private final CassandraSession session; | |||
|
|||
public TestingScyllaServer() | |||
throws Exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is test code. In tests is often more convenient to just declare throws Exception
and keep it, so that you won't need to add it ever again
Can we exclude the check on test resources?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that's possible per-check. Maybe we could create a separate configuration in maven-compiler-plugin
for tests?
...in/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/transactionlog/AddFileEntry.java
Show resolved
Hide resolved
testing/trino-testing/src/main/java/io/trino/testing/AbstractTestQueryFramework.java
Outdated
Show resolved
Hide resolved
Forcing the removal of a checked exception declaration from a method is a source-level backward incompatible change. Any callers that are calling such methods within a try-catch block will have to rewrite their code before they can compile. This is not good for the SPI, and also not good in keeping code changes localized. For example, given: class A
{
public static void main(String... args)
{
try {
B.run();
}
catch (java.io.IOException e) {
}
}
class B
{
public static void run()
throws java.io.IOException
{
...
}
} Forcing the removal of |
I agree that it is bad for interfaces and SPI, but other than that I would consider that an advantage (except for the bad change locality). If we know that some piece of code cannot throw a declared checked exception, this allows us to remove some potentially flaky error handling code, which was dead anyway. There is still an issue of unchecked exceptions, though. |
ee022be
to
8e7c166
Compare
The issue with this is that: * This is an experimental checker * It has a huge number of false negatives Regarding the second point, it may be that making it more accurate would make it unviably slow (the equivalent inspection in IntelliJ IDEA takes a lot of time, has to look at the whole code base - it's definitely not local - and has to be done repeatedly until nothing more is found). But perhaps it's still useful.
8e7c166
to
9d1c7a6
Compare
👋 @ksobolew - this PR has become inactive. If you're still interested in working on it, please let us know, and we can try to get reviewers to help with that. We're working on closing out old and inactive PRs, so if you're too busy or this has too many merge conflicts to be worth picking back up, we'll be making another pass to close it out in a few weeks. |
Hi @colebow, I think this change still has merit, but it looks like the Error Prone checker is still not precise enough to satisfy the community :) I'm going to close it, at least for now. |
@kokosing keeps wishing that this was on.
The issue with this is that:
Regarding the second point, it may be that making it more accurate would make it unviably slow (the equivalent inspection in IntelliJ IDEA takes a lot of time, has to look at the whole code base - it's definitely not local - and has to be done repeatedly until nothing more is found). But perhaps it's still useful.