mirror of
https://github.com/github/codeql.git
synced 2025-12-17 17:23:36 +01:00
98 lines
3.0 KiB
Java
98 lines
3.0 KiB
Java
package generatedtest;
|
|
|
|
import java.util.Optional;
|
|
import java.util.stream.Stream;
|
|
|
|
// Test case generated by GenerateFlowTestCase.ql
|
|
public class Test {
|
|
|
|
Object getElement(Optional<Object> container) { return container.get(); }
|
|
Object getStreamElement(Stream<Object> container) { return null; /* Modelled in .ql file */ }
|
|
Optional<Object> newWithElement(Object element) { return Optional.of(element); }
|
|
Object source() { return null; }
|
|
void sink(Object o) { }
|
|
|
|
public void test() {
|
|
|
|
{
|
|
// "java.util;Optional;false;filter;;;Element of Argument[-1];Element of ReturnValue;value"
|
|
Optional<Object> out = null;
|
|
Optional<Object> in = newWithElement(source());
|
|
out = in.filter(null);
|
|
sink(getElement(out)); // $hasValueFlow
|
|
}
|
|
{
|
|
// "java.util;Optional;false;get;;;Element of Argument[-1];ReturnValue;value"
|
|
Object out = null;
|
|
Optional<Object> in = newWithElement(source());
|
|
out = in.get();
|
|
sink(out); // $hasValueFlow
|
|
}
|
|
{
|
|
// "java.util;Optional;false;of;;;Argument[0];Element of ReturnValue;value"
|
|
Optional<Object> out = null;
|
|
Object in = (Object)source();
|
|
out = Optional.of(in);
|
|
sink(getElement(out)); // $hasValueFlow
|
|
}
|
|
{
|
|
// "java.util;Optional;false;ofNullable;;;Argument[0];Element of ReturnValue;value"
|
|
Optional<Object> out = null;
|
|
Object in = (Object)source();
|
|
out = Optional.ofNullable(in);
|
|
sink(getElement(out)); // $hasValueFlow
|
|
}
|
|
{
|
|
// "java.util;Optional;false;or;;;Element of Argument[-1];Element of ReturnValue;value"
|
|
Optional<Object> out = null;
|
|
Optional<Object> in = newWithElement(source());
|
|
out = in.or(null);
|
|
sink(getElement(out)); // $hasValueFlow
|
|
}
|
|
{
|
|
// "java.util;Optional;false;orElse;;;Argument[0];ReturnValue;value"
|
|
Object out = null;
|
|
Object in = (Object)source();
|
|
Optional<Object> instance = null;
|
|
out = instance.orElse(in);
|
|
sink(out); // $hasValueFlow
|
|
}
|
|
{
|
|
// "java.util;Optional;false;orElse;;;Element of Argument[-1];ReturnValue;value"
|
|
Object out = null;
|
|
Optional<Object> in = newWithElement(source());
|
|
out = in.orElse(null);
|
|
sink(out); // $hasValueFlow
|
|
}
|
|
{
|
|
// "java.util;Optional;false;orElseGet;;;Element of Argument[-1];ReturnValue;value"
|
|
Object out = null;
|
|
Optional<Object> in = newWithElement(source());
|
|
out = in.orElseGet(null);
|
|
sink(out); // $hasValueFlow
|
|
}
|
|
{
|
|
// "java.util;Optional;false;orElseThrow;;;Element of Argument[-1];ReturnValue;value"
|
|
Object out = null;
|
|
Optional<Object> in = newWithElement(source());
|
|
out = in.orElseThrow(null);
|
|
sink(out); // $hasValueFlow
|
|
}
|
|
{
|
|
// "java.util;Optional;false;orElseThrow;;;Element of Argument[-1];ReturnValue;value"
|
|
Object out = null;
|
|
Optional<Object> in = newWithElement(source());
|
|
out = in.orElseThrow();
|
|
sink(out); // $hasValueFlow
|
|
}
|
|
{
|
|
// "java.util;Optional;false;stream;;;Element of Argument[-1];Element of ReturnValue;value"
|
|
Stream<Object> out = null;
|
|
Optional<Object> in = newWithElement(source());
|
|
out = in.stream();
|
|
sink(getStreamElement(out)); // $hasValueFlow
|
|
}
|
|
|
|
}
|
|
|
|
} |