Java: Make a flow summary for Set.clear using WithoutElement and introduce appropriate tests.

This commit is contained in:
Michael Nebel
2023-08-07 09:50:30 +02:00
parent d3eb9c1325
commit 0ed724eb13
3 changed files with 13 additions and 2 deletions

View File

@@ -9,6 +9,7 @@ public class B {
static void sink(Object obj) { }
static Object[] storeArrayElement(Object obj) { return new Object[] {obj}; }
static Set storeSetElement(Object obj) { return Set.of(obj); }
static Object readArrayElement(Object[] obj) { return obj[0]; }
static boolean readArrayElement(boolean[] obj) { return obj[0]; }
@@ -1232,6 +1233,16 @@ public class B {
Map out = null;
Object[] in = storeArrayElement(storeMapValue(source())); out = Map.ofEntries((Map.Entry[])in); sink(readMapValue(out)); // $ hasValueFlow
}
{
// "java.util;Set;true;clear;;;Argument[this].WithoutElement;Argument[this];value;manual"
Set out = null;
Set in = storeSetElement(source()); out = in; out.clear(); sink(readElement(out)); // No flow
}
{
// "java.util;Set;true;clear;;;Argument[this].WithoutElement;Argument[this];value;manual"
Set out = null;
Set in = (Set)source(); out = in; out.clear(); sink(out); // $ hasValueFlow
}
{
// "java.util;Set;false;copyOf;(Collection);;Argument[0].Element;ReturnValue.Element;value;manual",
Set out = null;