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

Crash with -Adetailedmsgtext flag due to unescaped placeholders in diagnostic arguments #6919

Closed
iamsanjaymalakar opened this issue Dec 11, 2024 · 0 comments · Fixed by #6918
Assignees

Comments

@iamsanjaymalakar
Copy link
Member

The crash occurs with the -Adetailedmsgtext flag enabled while reporting a diagnostic message. If an argument contains unescaped placeholders like %x, they are mistakenly treated as part of the main format string instead of literal text. This causes formatting conflicts, leading to incomplete message generation and an exception when the placeholders clash with the expected format structure.

Stacktrace:

error: Invalid format string: "(purity.not.sideeffectfree.call) $$ 1 $$ new StringBuilder(10).append(String.format("$%x", displacement)).append("(a").append(regNumber).append $$ ( 34142, 34248 ) $$ call to side-effecting %s not allowed in side-effect-free method" args: [new StringBuilder(10).append(String.format("$%x", displacement)).append("(a").append(regNumber).append]
  ; The Checker Framework crashed.  Please report the crash.  Version: Checker Framework 3.48.2, branch HEAD, 2024-11-01, commit 59f4594, dirty=true. 
  Compilation unit: /home/smala009/RLF/cf-rlc/june2020_dataset_NJR/url542ae48576_tonyheadford_m68k_tgz-pJ8-m68k_MonitorJ8/src/m68k/cpu/CpuCore.java
  Last visited tree at line 1842 column 17:
  		public String toString()
  Exception: java.util.≈: x != com.sun.tools.javac.tree.JCTree$JCFieldAccess; java.util.IllegalFormatConversionException: x != com.sun.tools.javac.tree.JCTree$JCFieldAccess
  	at java.base/java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:4426)
  	at java.base/java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2938)
  	at java.base/java.util.Formatter$FormatSpecifier.print(Formatter.java:2892)
  	at java.base/java.util.Formatter.format(Formatter.java:2673)
  	at java.base/java.util.Formatter.format(Formatter.java:2609)
  	at java.base/java.lang.String.format(String.java:2897)
  	at org.checkerframework.framework.source.SourceChecker.report(SourceChecker.java:1464)
  	at org.checkerframework.framework.source.SourceChecker.reportError(SourceChecker.java:1382)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.reportPurityError(BaseTypeVisitor.java:1295)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.reportPurityErrors(BaseTypeVisitor.java:1267)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.checkPurityAnnotations(BaseTypeVisitor.java:1127)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.processMethodTree(BaseTypeVisitor.java:997)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.visitMethod(BaseTypeVisitor.java:954)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.visitMethod(BaseTypeVisitor.java:189)
  	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:898)
  	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
  	at org.checkerframework.framework.source.SourceVisitor.scan(SourceVisitor.java:92)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.scan(BaseTypeVisitor.java:408)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.scan(BaseTypeVisitor.java:189)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:90)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:105)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:113)
  	at jdk.compiler/com.sun.source.util.TreeScanner.visitClass(TreeScanner.java:187)
  	at org.checkerframework.framework.source.SourceVisitor.visitClass(SourceVisitor.java:98)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.processClassTree(BaseTypeVisitor.java:603)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.visitClass(BaseTypeVisitor.java:558)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.visitClass(BaseTypeVisitor.java:189)
  	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:808)
  	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
  	at org.checkerframework.framework.source.SourceVisitor.scan(SourceVisitor.java:92)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.scan(BaseTypeVisitor.java:408)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.scan(BaseTypeVisitor.java:189)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:90)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:105)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:113)
  	at jdk.compiler/com.sun.source.util.TreeScanner.visitClass(TreeScanner.java:187)
  	at org.checkerframework.framework.source.SourceVisitor.visitClass(SourceVisitor.java:98)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.processClassTree(BaseTypeVisitor.java:603)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.visitClass(BaseTypeVisitor.java:558)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.visitClass(BaseTypeVisitor.java:189)
  	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:808)
  	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:56)
  	at org.checkerframework.framework.source.SourceVisitor.visit(SourceVisitor.java:86)
  	at org.checkerframework.framework.source.SourceChecker.typeProcess(SourceChecker.java:1347)
  	at org.checkerframework.framework.source.SourceChecker.typeProcess(SourceChecker.java:1268)
  	at org.checkerframework.javacutil.AbstractTypeProcessor$AttributionTaskListener.finished(AbstractTypeProcessor.java:188)
  	at jdk.compiler/com.sun.tools.javac.api.ClientCodeWrapper$WrappedTaskListener.finished(ClientCodeWrapper.java:828)
  	at jdk.compiler/com.sun.tools.javac.api.MultiTaskListener.finished(MultiTaskListener.java:132)
  	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1417)
  	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1374)
  	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1515)
  	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1431)
  	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973)
  	at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:311)
  	at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:170)
  	at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
  	at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)

Reproducer:

reproducer.zip

chmod +x wpi.sh && ./wpi.sh url542ae48576_tonyheadford_m68k_tgz-pJ8-m68k_MonitorJ8

Fix:

The issue is resolved by escaping % in input arguments, replacing it with %% to ensure it is treated as literal text rather than a format specifier.

Environment

Checker Framework Version: 3.48.2
Commit: 59f4594
Java Version: OpenJDK 11.0.23 (2024-04-16)
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 a pull request may close this issue.

1 participant