geonetwork / core-geonetwork

GeoNetwork is a catalog application to manage spatially referenced resources. It provides powerful metadata editing and search functions as well as an interactive web map viewer. It is currently used in numerous Spatial Data Infrastructure initiatives across the world.
http://geonetwork-opensource.org/
GNU General Public License v2.0
412 stars 487 forks source link

[lucene] instantiation issue with the LuceneOptimizerManager #2771

Open pmauduit opened 6 years ago

pmauduit commented 6 years ago

Considering the following code: https://github.com/geonetwork/core-geonetwork/blob/develop/core/src/main/java/org/fao/geonet/kernel/search/LuceneOptimizerManager.java#L70-L74

If the first state of the optimizer is enabled set to false, the _beginAt member variable would never be initialized, causing any change in the admin UI (activating / deactivating the index optimizer) to fail with the following message:

Parameters saved but cannot restart Lucene Index Optimizer: **null**

Following the generated stacktrace lead me here:

https://github.com/geonetwork/core-geonetwork/blob/develop/core/src/main/java/org/fao/geonet/kernel/search/LuceneOptimizerManager.java?utf8=%E2%9C%93#L106

I guess the correct behaviour would be, regardless of the enabled value, to set the _beginAt variable in the constructor (even if the bean is actually deactivated).

PascalLike commented 6 years ago

If the error message "Parameters saved but cannot restart Lucene Index Optimizer: null" is thrown from here https://github.com/geonetwork/core-geonetwork/blob/cc04086527c8b47de54cfa332aab94240e9788ba/services/src/main/java/org/fao/geonet/api/site/SiteApi.java#L137 it calls this piece of code, where these attributes are initialized: https://github.com/geonetwork/core-geonetwork/blob/cc04086527c8b47de54cfa332aab94240e9788ba/core/src/main/java/org/fao/geonet/kernel/search/LuceneOptimizerManager.java#L110-L111

pmauduit commented 6 years ago

it calls this piece of code, where these attributes are initialized:

This code is not reached, because of the NPE thrown at line 106 (_beginAt being null)

PascalLike commented 6 years ago

Right! So better make this code more robust.