-
Notifications
You must be signed in to change notification settings - Fork 438
Add RLC-only SideEffectFree stubs and tests #7609
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
77d5a28
e1d5221
22fac31
d72e909
4abfe12
5d5fd21
e8970a4
2806c28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package java.lang; | ||
|
|
||
| import java.io.PrintStream; | ||
| import java.io.PrintWriter; | ||
| import org.checkerframework.checker.lock.qual.GuardSatisfied; | ||
| import org.checkerframework.dataflow.qual.SideEffectFree; | ||
|
|
||
| public interface AutoCloseable { | ||
| @SideEffectFree | ||
| void close(@GuardSatisfied AutoCloseable this) throws Exception; | ||
| } | ||
|
|
||
| public class Throwable { | ||
| @SideEffectFree | ||
| public void printStackTrace(); | ||
|
|
||
| @SideEffectFree | ||
| public void printStackTrace(PrintStream s); | ||
|
|
||
| @SideEffectFree | ||
| public void printStackTrace(PrintWriter s); | ||
| } | ||
|
|
||
| package java.io; | ||
|
|
||
| import org.checkerframework.checker.lock.qual.GuardSatisfied; | ||
| import org.checkerframework.dataflow.qual.SideEffectFree; | ||
|
|
||
| public interface Closeable extends AutoCloseable { | ||
| @SideEffectFree | ||
| public void close(@GuardSatisfied Closeable this) throws IOException; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import org.checkerframework.dataflow.qual.SideEffectFree; | ||
|
|
||
| // Log4j 1.x API stubs (package org.apache.log4j). | ||
| package org.apache.log4j; | ||
|
|
||
| class Logger { | ||
| @SideEffectFree public void debug(Object message); | ||
| @SideEffectFree public void warn(Object message); | ||
| @SideEffectFree public void error(Object message); | ||
| } | ||
|
Comment on lines
+6
to
+25
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Add regressions for the newly stubbed overload families. The new tests only hit Also applies to: 32-212 🤖 Prompt for AI Agents
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to cover representative samples from the stubs in the test cases, rather than adding test for every stub.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| // Log4j 2.x API stubs (package org.apache.logging.log4j). | ||
| package org.apache.logging.log4j; | ||
|
|
||
| interface Logger { | ||
| @SideEffectFree void debug(Object message); | ||
| @SideEffectFree void warn(Object message); | ||
| @SideEffectFree void error(Object message); | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // RLC uses Called Methods facts to remember that a resource has already been closed. | ||
| // This test checks that the RLC-specific SideEffectFree stub for AutoCloseable.close() | ||
| // preserves those facts across another close call in the same destructor, rather than | ||
| // conservatively forgetting them after the first invocation. | ||
|
|
||
| import org.checkerframework.checker.calledmethods.qual.EnsuresCalledMethods; | ||
| import org.checkerframework.checker.mustcall.qual.Owning; | ||
|
|
||
| final class TestAutoCloseable implements AutoCloseable { | ||
| @Override | ||
| public void close() {} | ||
| } | ||
|
|
||
| class AutoCloseableClose implements AutoCloseable { | ||
| private @Owning AutoCloseable first = new TestAutoCloseable(); | ||
| private @Owning AutoCloseable second = new TestAutoCloseable(); | ||
|
|
||
| @Override | ||
| @EnsuresCalledMethods( | ||
| value = {"this.first", "this.second"}, | ||
| methods = "close") | ||
| public void close() { | ||
| try { | ||
| first.close(); | ||
| second.close(); | ||
| } catch (Exception e) { | ||
| throw new AssertionError(e); | ||
| } | ||
| } | ||
iamsanjaymalakar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // RLC uses Called Methods facts to remember that a resource has already been closed. | ||
| // This test checks that the RLC-specific SideEffectFree stub for Closeable.close() | ||
| // preserves those facts across another close call in the same destructor, rather than | ||
| // conservatively forgetting them after the first invocation. | ||
|
|
||
| import java.io.Closeable; | ||
| import org.checkerframework.checker.calledmethods.qual.EnsuresCalledMethods; | ||
| import org.checkerframework.checker.mustcall.qual.Owning; | ||
|
|
||
| final class TestCloseable implements Closeable { | ||
| @Override | ||
| public void close() {} | ||
| } | ||
|
|
||
| class CloseableClose implements Closeable { | ||
| private @Owning Closeable first = new TestCloseable(); | ||
| private @Owning Closeable second = new TestCloseable(); | ||
|
|
||
| @Override | ||
| @EnsuresCalledMethods( | ||
| value = {"this.first", "this.second"}, | ||
| methods = "close") | ||
| public void close() { | ||
| try { | ||
| try { | ||
| first.close(); | ||
| } catch (Exception ignored) { | ||
| } | ||
| second.close(); | ||
| } catch (Exception e) { | ||
| throw new AssertionError(e); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // This test covers the Log4j 1.x API in package org.apache.log4j. | ||
| // The local Logger class below is just a tiny stand-in for the real library API. | ||
| // The RLC-specific stub marks debug/warn/error(Object) as @SideEffectFree, so | ||
| // logging after a resource is closed should not wipe out the close fact. | ||
|
|
||
| package org.apache.log4j; | ||
|
||
|
|
||
| import java.io.Closeable; | ||
| import org.checkerframework.checker.calledmethods.qual.EnsuresCalledMethods; | ||
| import org.checkerframework.checker.mustcall.qual.Owning; | ||
|
|
||
| class Logger { | ||
| public void debug(Object message) {} | ||
|
|
||
| public void warn(Object message) {} | ||
|
|
||
| public void error(Object message) {} | ||
| } | ||
|
|
||
| final class CloseableResource implements Closeable { | ||
| @Override | ||
| public void close() {} | ||
| } | ||
|
|
||
| class Log4j1DebugObject implements Closeable { | ||
| private final Logger logger = new Logger(); | ||
| private @Owning CloseableResource resource = new CloseableResource(); | ||
|
|
||
| @Override | ||
| @EnsuresCalledMethods(value = "this.resource", methods = "close") | ||
| public void close() { | ||
| resource.close(); | ||
| logger.debug("after close"); | ||
| } | ||
| } | ||
|
|
||
| class Log4j1WarnObject implements Closeable { | ||
| private final Logger logger = new Logger(); | ||
| private @Owning CloseableResource resource = new CloseableResource(); | ||
|
|
||
| @Override | ||
| @EnsuresCalledMethods(value = "this.resource", methods = "close") | ||
| public void close() { | ||
| resource.close(); | ||
| logger.warn("after close"); | ||
| } | ||
| } | ||
|
|
||
| class Log4j1ErrorObject implements Closeable { | ||
| private final Logger logger = new Logger(); | ||
| private @Owning CloseableResource resource = new CloseableResource(); | ||
|
|
||
| @Override | ||
| @EnsuresCalledMethods(value = "this.resource", methods = "close") | ||
| public void close() { | ||
| resource.close(); | ||
| logger.error("after close"); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| // This test covers the Log4j 2.x API in package org.apache.logging.log4j. | ||
| // The local Logger and LogManager declarations below are tiny stand-ins for the | ||
| // real library API. The RLC-specific stub marks Logger.debug/warn/error(Object) | ||
| // as @SideEffectFree, so logging after a resource is closed should not wipe out | ||
| // the close fact. | ||
|
|
||
| package org.apache.logging.log4j; | ||
|
||
|
|
||
| import java.io.Closeable; | ||
| import org.checkerframework.checker.calledmethods.qual.EnsuresCalledMethods; | ||
| import org.checkerframework.checker.mustcall.qual.Owning; | ||
|
|
||
| interface Logger { | ||
| void debug(Object message); | ||
|
|
||
| void warn(Object message); | ||
|
|
||
| void error(Object message); | ||
| } | ||
|
|
||
| final class SimpleLogger implements Logger { | ||
| @Override | ||
| public void debug(Object message) {} | ||
|
|
||
| @Override | ||
| public void warn(Object message) {} | ||
|
|
||
| @Override | ||
| public void error(Object message) {} | ||
| } | ||
|
|
||
| final class LogManager { | ||
| private LogManager() {} | ||
|
|
||
| static Logger getLogger() { | ||
| return new SimpleLogger(); | ||
| } | ||
| } | ||
|
|
||
| final class CloseableResource implements Closeable { | ||
| @Override | ||
| public void close() {} | ||
| } | ||
|
|
||
| class Log4j2DebugObject implements Closeable { | ||
| private static final Logger logger = LogManager.getLogger(); | ||
| private @Owning CloseableResource resource = new CloseableResource(); | ||
|
|
||
| @Override | ||
| @EnsuresCalledMethods(value = "this.resource", methods = "close") | ||
| public void close() { | ||
| resource.close(); | ||
| logger.debug("after close"); | ||
| } | ||
| } | ||
|
|
||
| class Log4j2WarnObject implements Closeable { | ||
| private static final Logger logger = LogManager.getLogger(); | ||
| private @Owning CloseableResource resource = new CloseableResource(); | ||
|
|
||
| @Override | ||
| @EnsuresCalledMethods(value = "this.resource", methods = "close") | ||
| public void close() { | ||
| resource.close(); | ||
| logger.warn("after close"); | ||
| } | ||
| } | ||
|
|
||
| class Log4j2ErrorObject implements Closeable { | ||
| private static final Logger logger = LogManager.getLogger(); | ||
| private @Owning CloseableResource resource = new CloseableResource(); | ||
|
|
||
| @Override | ||
| @EnsuresCalledMethods(value = "this.resource", methods = "close") | ||
| public void close() { | ||
| resource.close(); | ||
| logger.error("after close"); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // RLC-specific stubs mark Throwable.printStackTrace overloads as SideEffectFree so | ||
| // that debugging/logging after a resource is closed does not wipe out the close fact. | ||
| // This file checks the no-arg, PrintStream, and PrintWriter variants. | ||
|
|
||
| import java.io.Closeable; | ||
| import java.io.PrintStream; | ||
| import java.io.PrintWriter; | ||
| import java.io.StringWriter; | ||
| import org.checkerframework.checker.calledmethods.qual.EnsuresCalledMethods; | ||
| import org.checkerframework.checker.mustcall.qual.Owning; | ||
|
|
||
| final class CloseableResource implements Closeable { | ||
| @Override | ||
| public void close() {} | ||
| } | ||
|
|
||
| class ThrowablePrintStackTrace implements Closeable { | ||
| private @Owning CloseableResource resource = new CloseableResource(); | ||
|
|
||
| @Override | ||
| @EnsuresCalledMethods(value = "this.resource", methods = "close") | ||
| public void close() { | ||
| resource.close(); | ||
| new RuntimeException("debug").printStackTrace(); | ||
| } | ||
| } | ||
|
|
||
| class ThrowablePrintStackTracePrintStream implements Closeable { | ||
| private static final PrintStream STREAM = System.err; | ||
|
|
||
| private @Owning CloseableResource resource = new CloseableResource(); | ||
|
|
||
| @Override | ||
| @EnsuresCalledMethods(value = "this.resource", methods = "close") | ||
| public void close() { | ||
| resource.close(); | ||
| new RuntimeException("debug").printStackTrace(STREAM); | ||
| } | ||
| } | ||
|
|
||
| class ThrowablePrintStackTracePrintWriter implements Closeable { | ||
| private static final PrintWriter WRITER = new PrintWriter(new StringWriter()); | ||
|
|
||
| private @Owning CloseableResource resource = new CloseableResource(); | ||
|
|
||
| @Override | ||
| @EnsuresCalledMethods(value = "this.resource", methods = "close") | ||
| public void close() { | ||
| resource.close(); | ||
| new RuntimeException("debug").printStackTrace(WRITER); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.