Skip to content

Commit f86d454

Browse files
authored
fix(artifacts): an unresolved receiver type is not a dispatch site, not a NullPointerException (#265) (#266)
Set.of(...).contains(null) throws, and a call node's receiver_type is null whenever the receiver did not resolve, so 3.3.0-3.3.2 crashed every unbuilt project with a forward/include/sendRedirect call at every level.
1 parent 08860ae commit f86d454

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎src/main/java/com/ibm/cldk/artifacts/ViewDispatches.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ private static Site siteOf(String appName, JCallable callable, String localId, J
166166
String method = node.getMethodName();
167167
String via;
168168
String target;
169+
// An unresolved receiver (an unbuilt project, a missing jar) is null, and Set.of(...) throws
170+
// on contains(null): 3.3.0-3.3.2 crashed every such run at every level (#265). Not a site.
171+
if (receiver == null) {
172+
return null;
173+
}
169174
if (node.isConstructorCall() && MODEL_AND_VIEW.equals(receiver)) {
170175
if (arg0 == null) {
171176
return null; // `new ModelAndView()` names no view; setViewName will

‎src/test/java/com/ibm/cldk/artifacts/ViewDispatchesTest.java‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,24 @@ private static JViewDispatchUnresolved unresolved(String site) {
200200
+ result.unresolved.stream().map(JViewDispatchUnresolved::getSite)
201201
.collect(Collectors.toList())));
202202
}
203+
204+
// ---- an unbuilt project (#265) ---------------------------------------------------------------
205+
206+
@Test
207+
void anUnresolvableReceiverIsNotADispatchAndDoesNotCrash(@TempDir Path unbuilt) throws Exception {
208+
// No servlet stubs on this tree, so every receiver type here is unresolved. The pass must
209+
// simply see no site, not throw: Set.of(...).contains(null) is the NPE 3.3.0-3.3.2 shipped.
210+
ServletApiStubs.write(unbuilt, "src/main/java/demo/Front.java",
211+
"package demo;\n"
212+
+ "import javax.servlet.http.*;\n"
213+
+ "public class Front extends HttpServlet {\n"
214+
+ " protected void doGet(HttpServletRequest req, HttpServletResponse res) {\n"
215+
+ " req.getRequestDispatcher(\"/x.jsp\").forward(req, res);\n"
216+
+ " res.sendRedirect(\"/y.jsp\");\n"
217+
+ " }\n}\n");
218+
ServletApiStubs.write(unbuilt, "src/main/webapp/x.jsp", "<%= 1 %>");
219+
Map<String, JModule> mods = L1Extractor.extractAll(unbuilt, APP, null, new LinkedHashMap<>(), 1, 3, "ast");
220+
ViewDispatches.Result r = ViewDispatches.detect(APP, mods, ArtifactDiscovery.discover(unbuilt, APP, true, 262144));
221+
assertTrue(r.dispatches.isEmpty() && r.unresolved.isEmpty(), "unresolved receivers are not sites");
222+
}
203223
}

0 commit comments

Comments
 (0)