Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/com/ibm/cldk/artifacts/ViewDispatches.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ private static Site siteOf(String appName, JCallable callable, String localId, J
String method = node.getMethodName();
String via;
String target;
// An unresolved receiver (an unbuilt project, a missing jar) is null, and Set.of(...) throws
// on contains(null): 3.3.0-3.3.2 crashed every such run at every level (#265). Not a site.
if (receiver == null) {
return null;
}
if (node.isConstructorCall() && MODEL_AND_VIEW.equals(receiver)) {
if (arg0 == null) {
return null; // `new ModelAndView()` names no view; setViewName will
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/com/ibm/cldk/artifacts/ViewDispatchesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,24 @@ private static JViewDispatchUnresolved unresolved(String site) {
+ result.unresolved.stream().map(JViewDispatchUnresolved::getSite)
.collect(Collectors.toList())));
}

// ---- an unbuilt project (#265) ---------------------------------------------------------------

@Test
void anUnresolvableReceiverIsNotADispatchAndDoesNotCrash(@TempDir Path unbuilt) throws Exception {
// No servlet stubs on this tree, so every receiver type here is unresolved. The pass must
// simply see no site, not throw: Set.of(...).contains(null) is the NPE 3.3.0-3.3.2 shipped.
ServletApiStubs.write(unbuilt, "src/main/java/demo/Front.java",
"package demo;\n"
+ "import javax.servlet.http.*;\n"
+ "public class Front extends HttpServlet {\n"
+ " protected void doGet(HttpServletRequest req, HttpServletResponse res) {\n"
+ " req.getRequestDispatcher(\"/x.jsp\").forward(req, res);\n"
+ " res.sendRedirect(\"/y.jsp\");\n"
+ " }\n}\n");
ServletApiStubs.write(unbuilt, "src/main/webapp/x.jsp", "<%= 1 %>");
Map<String, JModule> mods = L1Extractor.extractAll(unbuilt, APP, null, new LinkedHashMap<>(), 1, 3, "ast");
ViewDispatches.Result r = ViewDispatches.detect(APP, mods, ArtifactDiscovery.discover(unbuilt, APP, true, 262144));
assertTrue(r.dispatches.isEmpty() && r.unresolved.isEmpty(), "unresolved receivers are not sites");
}
}