Created
May 15, 2017 20:17
-
-
Save dr2chase/3a9160901e8a5a3f9ed057c4d0e20cf3 to your computer and use it in GitHub Desktop.
Shell script that unpacks and runs a Java bug. Verification does not ensure static correctness of interface types.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo "interface I1 { }" > I1.java | |
echo "interface I2 { }" > I2.java | |
echo "interface I3 { }" > I3.java | |
echo "class I1I2 implements I1, I2 { }" > I1I2.java_good | |
echo "class I1I2 implements I1 { }" > I1I2.java_bad | |
echo "class I1I3I2 implements I1, I3, I2 { }" > I1I3I2.java | |
cat > tricky.java <<'//EOF' | |
class tricky { | |
I2 i2; | |
static I2 si2; | |
boolean isI2(Object x) { | |
return (x == null) || (x instanceof I2); | |
} | |
void expectsI2(I2 x) { | |
String result = isI2(x) ? "pass" : "fail"; | |
System.err.println(result); | |
} | |
I2 cloaksI2(boolean b, I1I2 x, I1I3I2 y) { | |
I2 i2 = b ? (I2) x : (I2) y; | |
this.i2 = i2; | |
si2 = i2; | |
expectsI2(i2); | |
return i2; | |
} | |
public static void main(String args[]) { | |
tricky t = new tricky(); | |
t.expectsI2(t.cloaksI2(true, new I1I2(), new I1I3I2())); | |
t.expectsI2(t.i2); | |
t.expectsI2(si2); | |
} | |
} | |
//EOF | |
cp I1I2.java_good I1I2.java | |
javac tricky.java | |
# You might expect this here would cause verification problems in the future. | |
cp I1I2.java_bad I1I2.java | |
javac I1I2.java | |
# But no... | |
java -verify -Xfuture -cp . tricky | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment