Index Checker crash: "Cannot be negated: a class java.lang.Character" on (char) ('a' + i)
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Start in ValueLiteral.negateBoxedPrimitive, named in the stack trace, and trace how DependentTypesHelper parses the offset for the cast expression. Reproduce with the supplied CharCast.java and javac command under JDK 25; done means the checker no longer crashes on this case. Linked pull request #8321 indicates work is already underway.
Written by the indexing model from the issue text.
Description
The Index Checker crashes on a char cast of 'a' + i, where i is bounded by an array length.
Test case CharCast.java:
public class CharCast {
static void m(String[] a, int i) {
if (i < a.length) {
char c = (char) ('a' + i);
}
}
}
Command:
javac -processor index -proc:only CharCast.java
Output:
error: Cannot be negated: a class java.lang.Character
; The Checker Framework crashed. Please report the crash.
Compilation unit: CharCast.java
Last visited tree at line 4 column 16:
char c = (char) ('a' + i);
Exception: org.checkerframework.javacutil.BugInCF: Cannot be negated: a class java.lang.Character; org.checkerframework.javacutil.BugInCF: Cannot be negated: a class java.lang.Character
at org.checkerframework.dataflow.expression.ValueLiteral.negateBoxedPrimitive(ValueLiteral.java:91)
at org.checkerframework.dataflow.expression.ValueLiteral.negate(ValueLiteral.java:57)
at org.checkerframework.dataflow.expression.ExpressionTreeToJavaExpressionVisitor.visitUnary(ExpressionTreeToJavaExpressionVisitor.java:869)
at org.checkerframework.dataflow.expression.ExpressionTreeToJavaExpressionVisitor.visitUnary(ExpressionTreeToJavaExpressionVisitor.java:58)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCUnary.accept(JCTree.java:2193)
at org.checkerframework.dataflow.expression.ExpressionTreeToJavaExpressionVisitor.convert(ExpressionTreeToJavaExpressionVisitor.java:176)
at org.checkerframework.dataflow.expression.JavaExpressionParseUtil.parse(JavaExpressionParseUtil.java:87)
at org.checkerframework.framework.util.StringToJavaExpression.atPath(StringToJavaExpression.java:341)
at org.checkerframework.framework.util.dependenttypes.DependentTypesHelper.lambda$atExpression$10(DependentTypesHelper.java:543)
at org.checkerframework.framework.util.dependenttypes.DependentTypesHelper.convertAnnotationMirror(DependentTypesHelper.java:801)
at org.checkerframework.framework.util.dependenttypes.DependentTypesHelper.lambda$convertAnnotatedTypeMirror$13(DependentTypesHelper.java:753)
at org.checkerframework.framework.util.dependenttypes.DependentTypesHelper$AnnotatedTypeReplacer.scan(DependentTypesHelper.java:965)
at org.checkerframework.framework.util.dependenttypes.DependentTypesHelper$AnnotatedTypeReplacer.scan(DependentTypesHelper.java:925)
at org.checkerframework.framework.type.visitor.AnnotatedTypeScanner.visit(AnnotatedTypeScanner.java:194)
at org.checkerframework.framework.util.dependenttypes.DependentTypesHelper.convertAnnotatedTypeMirror(DependentTypesHelper.java:753)
at org.checkerframework.framework.util.dependenttypes.DependentTypesHelper.atExpression(DependentTypesHelper.java:549)
at org.checkerframework.framework.util.dependenttypes.DependentTypesTreeAnnotator.visitTypeCast(DependentTypesTreeAnnotator.java:47)
at org.checkerframework.framework.util.dependenttypes.DependentTypesTreeAnnotator.visitTypeCast(DependentTypesTreeAnnotator.java:22)
Probable cause: the type of 'a' + i gets a dependent annotation such as @LTLengthOf(value = "a", offset = "-'a'"). When DependentTypesHelper parses that offset, ValueLiteral.negateBoxedPrimitive does not handle Character.
The crash reproduces with Checker Framework 4.2.0 and with current master (0091b16), under JDK 25. I found it in Daikon (https://github.com/codespecs/daikon/pull/854).
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 154
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from typetools/checker-framework
-
4.3.0: BitSet.clear() fails with flowexpr.parse.index.too.big — @SideEffectsOnly("#1") on a no-arg methodPossibly taken @mernst claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
typetools/checker-framework#8325 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
typetools/checker-framework#8043 ·
Maintainers usually reply within 1 day
-
Enforce `@TargetLocations`Possibly taken @w3lld1 claimed this 35 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 85/100
typetools/checker-framework#8042 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
typetools/checker-framework#7096 · 1 comment ·
Maintainers usually reply within 1 day
-
Crash in CFG construction when unboxing an Integer-bounded type variablePossibly taken @msridhar claimed this 1 day ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 20/100
typetools/checker-framework#8328 ·
Maintainers usually reply within 1 day
All issues in typetools/checker-framework
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
PCL-Community/PCL-CE#3658 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Team/Identity Server Core Type/Improvement U2
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
wso2/product-is#28553 ·
Maintainers usually reply within 1 day
-
frontend
Difficulty 1/5 Under an hour Newbie friendliness 72/100
Paul-Austin-Oswego-CSC480-HCI521/gift-app#116 ·
Maintainers usually reply within 2 days
-
dependencies java
Difficulty 1/5 Under an hour Newbie friendliness 62/100
micrometer-metrics/tracing#1588 ·
Maintainers usually reply within 1 day