Performing a WMTS GetCapabilities request with layer groups provokes a NPE

Description

To reproduce this error just perform a WMTS get capabilities request where group layers are included, a NULL pointer exception will be throw (full stack trace attached):

1 2 3 4 java.lang.NullPointerException at java.util.HashMap.putMapEntries(HashMap.java:500) at java.util.HashMap.putAll(HashMap.java:784) at org.geowebcache.service.wmts.WMTSGetCapabilities.getLegendsInfo(WMTSGetCapabilities.java:516)

This happens because GeoServer doesn't returns an empty map (default behavior of the overridden method) but instead NULL when no legends are available. This typically happens for layer groups which don't have legends associated.

The line of code that does this:
https://github.com/geoserver/geoserver/blob/master/src/gwc/src/main/java/org/geoserver/gwc/layer/GeoServerTileLayer.java#L1277-L1280

GWC code can also be made more robust by ignoring NULL values.

Environment

None

Status

Assignee

Nuno Oliveira

Reporter

Nuno Oliveira

Triage

None

Fix versions

Affects versions

None

Components

Priority

Medium
Configure