Skip to content

Commit e23f666

Browse files
Replace get and newWith methods with real implementations
1 parent f1ca29a commit e23f666

File tree

2 files changed

+54
-40
lines changed

2 files changed

+54
-40
lines changed

java/ql/test/library-tests/frameworks/guava/generated/cache/Test.java

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,133 +2,161 @@
22

33
import com.google.common.cache.Cache;
44
import com.google.common.cache.LoadingCache;
5+
import com.google.common.cache.CacheBuilder;
56
import com.google.common.collect.ImmutableMap;
67
import java.util.Map;
78
import java.util.concurrent.ConcurrentMap;
9+
import java.util.HashMap;
10+
import java.util.List;
11+
import java.util.ArrayList;
812

913
// Test case generated by GenerateFlowTestCase.ql
1014
public class Test {
1115

12-
Object getMapKey(Object container) { return null; }
13-
Object getMapValue(Object container) { return null; }
14-
Object newWithElement(Object element) { return null; }
15-
Object newWithMapKey(Object element) { return null; }
16-
Object newWithMapValue(Object element) { return null; }
17-
Object source() { return null; }
16+
<K,V> K getMapKey(Map<K,V> container) { return container.keySet().iterator().next(); }
17+
<K,V> K getMapKey(Cache<K,V> container) { return getMapKey(container.asMap()); }
18+
<K,V> V getMapValue(Map<K,V> container) { return container.values().iterator().next(); }
19+
<K,V> V getMapValue(Cache<K,V> container) { return getMapValue(container.asMap()); }
20+
<T> Iterable<T> newWithElement(T element) {
21+
List<T> l = new ArrayList();
22+
l.add(element);
23+
return l;
24+
}
25+
<K,V> Map<K,V> newMapWithMapKey(K element) {
26+
Map<K,V> m = new HashMap<K,V>();
27+
m.put(element, null);
28+
return m;
29+
}
30+
<K,V> LoadingCache<K,V> newCacheWithMapKey(K element) {
31+
LoadingCache<K,V> lc = CacheBuilder.newBuilder().build(null);
32+
lc.put(element, null);
33+
return lc;
34+
}
35+
<K,V> Map<K,V> newMapWithMapValue(V element) {
36+
Map<K,V> m = new HashMap<K,V>();
37+
m.put(null, element);
38+
return m;
39+
}
40+
<K,V> LoadingCache<K,V> newCacheWithMapValue(V element) {
41+
LoadingCache<K,V> lc = CacheBuilder.newBuilder().build(null);
42+
lc.put(null, element);
43+
return lc;
44+
}
45+
<T> T source() { return null; }
1846
void sink(Object o) { }
1947

2048
public void test() throws Exception {
2149

2250
{
2351
// "com.google.common.cache;Cache;true;asMap;();;MapKey of Argument[-1];MapKey of ReturnValue;value"
2452
ConcurrentMap out = null;
25-
LoadingCache in = (LoadingCache)newWithMapKey(source());
53+
LoadingCache in = newCacheWithMapKey(source());
2654
out = in.asMap();
2755
sink(getMapKey(out)); // $ hasValueFlow
2856
}
2957
{
3058
// "com.google.common.cache;Cache;true;asMap;();;MapKey of Argument[-1];MapKey of ReturnValue;value"
3159
ConcurrentMap out = null;
32-
Cache in = (Cache)newWithMapKey(source());
60+
Cache in = newCacheWithMapKey(source());
3361
out = in.asMap();
3462
sink(getMapKey(out)); // $ hasValueFlow
3563
}
3664
{
3765
// "com.google.common.cache;Cache;true;asMap;();;MapValue of Argument[-1];MapValue of ReturnValue;value"
3866
ConcurrentMap out = null;
39-
LoadingCache in = (LoadingCache)newWithMapValue(source());
67+
LoadingCache in = newCacheWithMapValue(source());
4068
out = in.asMap();
4169
sink(getMapValue(out)); // $ hasValueFlow
4270
}
4371
{
4472
// "com.google.common.cache;Cache;true;asMap;();;MapValue of Argument[-1];MapValue of ReturnValue;value"
4573
ConcurrentMap out = null;
46-
Cache in = (Cache)newWithMapValue(source());
74+
Cache in = newCacheWithMapValue(source());
4775
out = in.asMap();
4876
sink(getMapValue(out)); // $ hasValueFlow
4977
}
5078
{
5179
// "com.google.common.cache;Cache;true;get;(Object,Callable);;MapValue of Argument[-1];ReturnValue;value"
5280
Object out = null;
53-
Cache in = (Cache)newWithMapValue(source());
81+
Cache in = newCacheWithMapValue(source());
5482
out = in.get(null, null);
5583
sink(out); // $ hasValueFlow
5684
}
5785
{
5886
// "com.google.common.cache;Cache;true;getAllPresent;(Iterable);;MapValue of Argument[-1];MapValue of ReturnValue;value"
5987
ImmutableMap out = null;
60-
Cache in = (Cache)newWithMapValue(source());
88+
Cache in = newCacheWithMapValue(source());
6189
out = in.getAllPresent(null);
6290
sink(getMapValue(out)); // $ hasValueFlow
6391
}
6492
{
65-
// "com.google.common.cache;Cache;true;getIfPresent;(Object);;MapValue of Argument[-1];ReturnValue;value"
93+
// "com.google.common.cache;Cache;true;getIfPresent;;;MapValue of Argument[-1];ReturnValue;value"
6694
Object out = null;
67-
Cache in = (Cache)newWithMapValue(source());
95+
Cache in = newCacheWithMapValue(source());
6896
out = in.getIfPresent(null);
6997
sink(out); // $ hasValueFlow
7098
}
7199
{
72100
// "com.google.common.cache;Cache;true;put;(Object,Object);;Argument[0];MapKey of Argument[-1];value"
73101
Cache out = null;
74-
Object in = (Object)source();
102+
Object in = source();
75103
out.put(in, null);
76104
sink(getMapKey(out)); // $ hasValueFlow
77105
}
78106
{
79107
// "com.google.common.cache;Cache;true;put;(Object,Object);;Argument[1];MapValue of Argument[-1];value"
80108
Cache out = null;
81-
Object in = (Object)source();
109+
Object in = source();
82110
out.put(null, in);
83111
sink(getMapValue(out)); // $ hasValueFlow
84112
}
85113
{
86114
// "com.google.common.cache;Cache;true;putAll;(Map);;MapKey of Argument[0];MapKey of Argument[-1];value"
87115
Cache out = null;
88-
Map in = (Map)newWithMapKey(source());
116+
Map in = newMapWithMapKey(source());
89117
out.putAll(in);
90118
sink(getMapKey(out)); // $ hasValueFlow
91119
}
92120
{
93121
// "com.google.common.cache;Cache;true;putAll;(Map);;MapValue of Argument[0];MapValue of Argument[-1];value"
94122
Cache out = null;
95-
Map in = (Map)newWithMapValue(source());
123+
Map in = newMapWithMapValue(source());
96124
out.putAll(in);
97125
sink(getMapValue(out)); // $ hasValueFlow
98126
}
99127
{
100-
// "com.google.common.cache;LoadingCache;true;apply;(Object);;MapValue of Argument[-1];ReturnValue;value"
128+
// "com.google.common.cache;LoadingCache;true;apply;;;MapValue of Argument[-1];ReturnValue;value"
101129
Object out = null;
102-
LoadingCache in = (LoadingCache)newWithMapValue(source());
130+
LoadingCache in = newCacheWithMapValue(source());
103131
out = in.apply(null);
104132
sink(out); // $ hasValueFlow
105133
}
106134
{
107-
// "com.google.common.cache;LoadingCache;true;get;(Object);;MapValue of Argument[-1];ReturnValue;value"
135+
// "com.google.common.cache;LoadingCache;true;get;;;MapValue of Argument[-1];ReturnValue;value"
108136
Object out = null;
109-
LoadingCache in = (LoadingCache)newWithMapValue(source());
137+
LoadingCache in = newCacheWithMapValue(source());
110138
out = in.get(null);
111139
sink(out); // $ hasValueFlow
112140
}
113141
{
114142
// "com.google.common.cache;LoadingCache;true;getAll;(Iterable);;Element of Argument[0];MapKey of ReturnValue;value"
115143
ImmutableMap out = null;
116-
Iterable in = (Iterable)newWithElement(source());
144+
Iterable in = newWithElement(source());
117145
LoadingCache instance = null;
118146
out = instance.getAll(in);
119147
sink(getMapKey(out)); // $ hasValueFlow
120148
}
121149
{
122150
// "com.google.common.cache;LoadingCache;true;getAll;(Iterable);;MapValue of Argument[-1];MapValue of ReturnValue;value"
123151
ImmutableMap out = null;
124-
LoadingCache in = (LoadingCache)newWithMapValue(source());
152+
LoadingCache in = newCacheWithMapValue(source());
125153
out = in.getAll(null);
126154
sink(getMapValue(out)); // $ hasValueFlow
127155
}
128156
{
129-
// "com.google.common.cache;LoadingCache;true;getUnchecked;(Object);;MapValue of Argument[-1];ReturnValue;value"
157+
// "com.google.common.cache;LoadingCache;true;getUnchecked;;;MapValue of Argument[-1];ReturnValue;value"
130158
Object out = null;
131-
LoadingCache in = (LoadingCache)newWithMapValue(source());
159+
LoadingCache in = newCacheWithMapValue(source());
132160
out = in.getUnchecked(null);
133161
sink(out); // $ hasValueFlow
134162
}

java/ql/test/library-tests/frameworks/guava/generated/cache/test.ql

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,6 @@ import semmle.code.java.dataflow.ExternalFlow
44
import semmle.code.java.dataflow.TaintTracking
55
import TestUtilities.InlineExpectationsTest
66

7-
class SummaryModelTest extends SummaryModelCsv {
8-
override predicate row(string row) {
9-
row =
10-
[
11-
//"package;type;overrides;name;signature;ext;inputspec;outputspec;kind",
12-
"generatedtest;Test;false;newWithElement;;;Argument[0];Element of ReturnValue;value",
13-
"generatedtest;Test;false;getMapKey;;;MapKey of Argument[0];ReturnValue;value",
14-
"generatedtest;Test;false;newWithMapKey;;;Argument[0];MapKey of ReturnValue;value",
15-
"generatedtest;Test;false;getMapValue;;;MapValue of Argument[0];ReturnValue;value",
16-
"generatedtest;Test;false;newWithMapValue;;;Argument[0];MapValue of ReturnValue;value"
17-
]
18-
}
19-
}
20-
217
class ValueFlowConf extends DataFlow::Configuration {
228
ValueFlowConf() { this = "qltest:valueFlowConf" }
239

0 commit comments

Comments
 (0)