Skip to content

Commit

Permalink
fix: avoid NPE in LookupServletContainerInitializer (#11233) (#11238)
Browse files Browse the repository at this point in the history
fixes #11218

Co-authored-by: Denis <denis@vaadin.com>
  • Loading branch information
vaadin-bot and Denis committed Jun 15, 2021
1 parent baf0976 commit e1956ff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ public class LookupServletContainerInitializer
@Override
public void process(Set<Class<?>> classSet, ServletContext servletContext)
throws ServletException {
if (classSet == null) {
throw new ServletException(ServletContainerInitializer.class
.getSimpleName() + " is called but the "
+ "provided set of classes is 'null'. "
+ LookupInitializer.class + " always presents "
+ "and has to be passed to the 'onStartup' method as an argument "
+ "in the set of classes if the servlet container supports Servlet 3.0 specification. "
+ "The propject configuration is broken somehow or you are using Servlet 3.0 incompatible container.");
}
if (!classSet.contains(LookupInitializer.class)) {
// this is a specific case for OSGi (PAX web): at some point it may
// decide to apply ServletContainerInitializers for non WAR case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ protected Collection<Class<?>> getServiceTypes() {
Assert.assertEquals(ArrayList.class, collection.iterator().next());
}

@Test(expected = ServletException.class)
public void process_classSetIsNull_throws() throws ServletException {
initializer.process(null, Mockito.mock(ServletContext.class));
}

private Lookup mockLookup(ServletContext context, Class<?>... classes)
throws ServletException {
ArgumentCaptor<Lookup> lookupCapture = ArgumentCaptor
Expand Down

0 comments on commit e1956ff

Please sign in to comment.