java-topology/test/langtools/tools/javac/ParseConditional.java
russell@unturf.com 0a580b313d undefect. CWE-407 — 63 sites patched across 27 ecosystems
Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com

Patches, unit tests, benchmarks, whitepaper, and outreach briefs.
Public domain — no copyright claimed. Use freely.
2026-03-26 17:11:57 -04:00

25 lines
830 B
Java

/*
* @test /nodynamiccopyright/
* @bug 4092958
* @summary The compiler was too permissive in its parsing of conditional
* expressions.
* @author turnidge
*
* @compile/fail/ref=ParseConditional.out -XDrawDiagnostics ParseConditional.java
*/
public class ParseConditional {
public static void meth() {
boolean condition = true;
int a = 1;
int b = 2;
int c = 3;
int d = 4;
// The following line should give an error because the conditional ?: operator
// is higher priority than the final assignment operator, between c and d.
// As such, the correct parsing is:
// a = (condition ? b = c : c) = d;
// and it is illegal to try and assign to the value of the conditional expression.
a = condition ? b = c : c = d;
}
}