Skip to content

Commit 768a8e7

Browse files
committed
Fixup JaxRs.ql to cope with stubbed MediaType file
In a real-world situation this type would be defined in an imported jar, but since here it is defined in a stub the getADeclaredContentType routine can see it is defined as an empty string in the stubbed implementation. Filter these out so the test more closely resembles the real situation.
1 parent 8eaffaf commit 768a8e7

File tree

1 file changed

+17
-3
lines changed
  • java/ql/test/library-tests/frameworks/JaxWs

1 file changed

+17
-3
lines changed

java/ql/test/library-tests/frameworks/JaxWs/JaxRs.ql

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,16 @@ class JaxRsTest extends InlineExpectationsTest {
2424
resourceMethod.getLocation() = location and
2525
element = resourceMethod.toString() and
2626
if exists(resourceMethod.getProducesAnnotation())
27-
then value = resourceMethod.getProducesAnnotation().getADeclaredContentType()
28-
else value = ""
27+
then
28+
value = resourceMethod.getProducesAnnotation().getADeclaredContentType() and
29+
value != ""
30+
else
31+
// Filter out empty strings that stem from using stubs.
32+
// If we built the test against the real JAR then the field
33+
// access against e.g. MediaType.APPLICATION_JSON wouldn't
34+
// be a CompileTimeConstantExpr at all, whereas in the stubs
35+
// it is and is defined empty.
36+
value = ""
2937
)
3038
or
3139
tag = "RootResourceClass" and
@@ -135,7 +143,13 @@ class JaxRsTest extends InlineExpectationsTest {
135143
exists(JaxRSProducesAnnotation producesAnnotation |
136144
producesAnnotation.getLocation() = location and
137145
element = producesAnnotation.toString() and
138-
value = producesAnnotation.getADeclaredContentType()
146+
value = producesAnnotation.getADeclaredContentType() and
147+
value != ""
148+
// Filter out empty strings that stem from using stubs.
149+
// If we built the test against the real JAR then the field
150+
// access against e.g. MediaType.APPLICATION_JSON wouldn't
151+
// be a CompileTimeConstantExpr at all, whereas in the stubs
152+
// it is and is defined empty.
139153
)
140154
or
141155
tag = "ConsumesAnnotation" and

0 commit comments

Comments
 (0)