JDBCConfig fails to import data dir with NPE

Description

I tried to import again a data dir I'm keeping for testing, has 1000 workspaces and over 40k layers... used to import, now it fails during the startup with the following log:

```
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'advertisedCatalog' defined in URL [jar:file:/home/aaime/devel/cluster-tests/geoserver-2.17-SNAPSHOT-jdbc1/webapps/geoserver/WEB-INF/lib/gs-main-2.17-SNAPSHOT.jar!/applicationContext.xml]: Cannot resolve reference to bean 'secureCatalog' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accessRulesDao' defined in URL [jar:file:/home/aaime/devel/cluster-tests/geoserver-2.17-SNAPSHOT-jdbc1/webapps/geoserver/WEB-INF/lib/gs-main-2.17-SNAPSHOT.jar!/applicationSecurityContext.xml]: Cannot resolve reference to bean 'rawCatalog' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rawCatalog' defined in URL [jar:file:/home/aaime/devel/cluster-tests/geoserver-2.17-SNAPSHOT-jdbc1/webapps/geoserver/WEB-INF/lib/gs-main-2.17-SNAPSHOT.jar!/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.RuntimeException: java.lang.reflect.UndeclaredThrowableException
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:314)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:110)
at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:676)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:188)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1340)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1186)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:303)
... 84 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accessRulesDao' defined in URL [jar:file:/home/aaime/devel/cluster-tests/geoserver-2.17-SNAPSHOT-jdbc1/webapps/geoserver/WEB-INF/lib/gs-main-2.17-SNAPSHOT.jar!/applicationSecurityContext.xml]: Cannot resolve reference to bean 'rawCatalog' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rawCatalog' defined in URL [jar:file:/home/aaime/devel/cluster-tests/geoserver-2.17-SNAPSHOT-jdbc1/webapps/geoserver/WEB-INF/lib/gs-main-2.17-SNAPSHOT.jar!/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.RuntimeException: java.lang.reflect.UndeclaredThrowableException
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:314)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:110)
at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:676)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:188)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1340)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1186)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:307)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:303)
... 96 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rawCatalog' defined in URL [jar:file:/home/aaime/devel/cluster-tests/geoserver-2.17-SNAPSHOT-jdbc1/webapps/geoserver/WEB-INF/lib/gs-main-2.17-SNAPSHOT.jar!/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.RuntimeException: java.lang.reflect.UndeclaredThrowableException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:601)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:303)
... 110 more
Caused by: java.lang.RuntimeException: java.lang.reflect.UndeclaredThrowableException
at org.geoserver.config.GeoServerLoader.postProcessBeforeInitialization(GeoServerLoader.java:266)
at org.geoserver.config.GeoServerLoaderProxy.postProcessBeforeInitialization(GeoServerLoaderProxy.java:57)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:414)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1763)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593)
... 116 more
Caused by: java.lang.reflect.UndeclaredThrowableException
at com.sun.proxy.$Proxy28.syncTo(Unknown Source)
at org.geoserver.catalog.impl.CatalogImpl.sync(CatalogImpl.java:1989)
at org.geoserver.config.GeoServerLoader.readCatalog(GeoServerLoader.java:400)
at org.geoserver.jdbcconfig.JDBCGeoServerLoader.loadCatalogInternal(JDBCGeoServerLoader.java:91)
at org.geoserver.jdbcconfig.JDBCGeoServerLoader.loadCatalog(JDBCGeoServerLoader.java:78)
at org.geoserver.config.GeoServerLoader.postProcessBeforeInitialization(GeoServerLoader.java:261)
... 120 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.geoserver.catalog.LockingCatalogFacade.invoke(LockingCatalogFacade.java:36)
... 126 more
Caused by: java.lang.NullPointerException
at org.geoserver.jdbcconfig.internal.ConfigDatabase.lookUpRelatedObject(ConfigDatabase.java:714)
at org.geoserver.jdbcconfig.internal.ConfigDatabase.addAttribute(ConfigDatabase.java:603)
at org.geoserver.jdbcconfig.internal.ConfigDatabase.addAttributes(ConfigDatabase.java:579)
at org.geoserver.jdbcconfig.internal.ConfigDatabase.add(ConfigDatabase.java:548)
at org.geoserver.jdbcconfig.internal.ConfigDatabase$$FastClassBySpringCGLIB$$dd464281.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:750)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:295)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689)
at org.geoserver.jdbcconfig.internal.ConfigDatabase$$EnhancerBySpringCGLIB$$f602b7d0.add(<generated>)
at org.geoserver.jdbcconfig.catalog.JDBCCatalogFacade.addInternal(JDBCCatalogFacade.java:902)
at org.geoserver.jdbcconfig.catalog.JDBCCatalogFacade.add(JDBCCatalogFacade.java:297)
at org.geoserver.catalog.impl.DefaultCatalogFacade.syncTo(DefaultCatalogFacade.java:991)
at org.geoserver.catalog.impl.IsolatedCatalogFacade.syncTo(IsolatedCatalogFacade.java:471)
```

The code in question seems to turn a non null list of values into a null value, and then goes "boom" trying to get a class out of it. But I could not debug exactly what's the dangling reference about. If anyone is interested I have the (massive) data dir available.

Environment

None

Assignee

Unassigned

Reporter

Andrea Aime

Triage

None

Fix versions

None

Affects versions

None

Components

Priority

Medium
Configure