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.
This commit is contained in:
commit
0a580b313d
70422 changed files with 17213626 additions and 0 deletions
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8304487
|
||||
* @summary Compiler Implementation for Primitive types in patterns, instanceof, and switch (Preview)
|
||||
* @enablePreview
|
||||
* @compile/fail/ref=PrimitiveInstanceOfErrors.out -XDrawDiagnostics -XDshould-stop.at=FLOW PrimitiveInstanceOfErrors.java
|
||||
*/
|
||||
public class PrimitiveInstanceOfErrors {
|
||||
public static boolean unboxingAndNarrowingPrimitiveNotAllowedPerCastingConversion() {
|
||||
Long l_within_int_range = 42L;
|
||||
Long l_outside_int_range = 999999999999999999L;
|
||||
|
||||
return l_within_int_range instanceof int && !(l_outside_int_range instanceof int);
|
||||
}
|
||||
|
||||
public static <T extends Integer> boolean wideningReferenceConversionUnboxingAndNarrowingPrimitive(T i) {
|
||||
return i instanceof byte;
|
||||
}
|
||||
|
||||
public static void boxingConversionsBetweenIncompatibleTypes() {
|
||||
int i = 42;
|
||||
|
||||
boolean ret1 = i instanceof Integer; // (Integer) i // OK and true
|
||||
boolean ret2 = i instanceof Double; // error: incompatible types
|
||||
boolean ret3 = i instanceof Short; // error: incompatible types
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue