Hello! I would like to propose PR for fix empty config files. This fix concerns the main module of geoserver - I'm not sure if an outsider can make such PR?
Here I described the problem: https://osgeo-org.atlassian.net/browse/GEOS-9244 I see that the code that populates the file with the default values is located in the catch block in the loadProperties method: https://github.com/geoserver/geoserver/blob/master/src/main/src/main/java/org/geoserver/config/GeoServerPropertyConfigurer.java#L101 However, during debugging, I've observed that FileNotFoundException is never thrown by the loadProperties of the PropertiesLoaderSupport Spring class. After exiting this method, the file is already created (empty). I propose to remove try-catch block and to check if config file is empty instead: @Override protected void loadProperties(Properties props) throws IOException { super.loadProperties(props); if (configFile != null && copyOutTemplate && configFile.file().length() == 0) { try (OutputStream fout = configFile.out()) { props.store(fout, comments); fout.flush(); } } } I'm not sure about the use of file() method (it has side effects - creates a file) in this case, but I have no other idea. What do you think about it? I also added a new test method detecting this error: @Test public void testSaveDefaultsToConfigFile() throws IOException { FileInputStream in = new FileInputStream("target/foo.properties"); Properties prop = new Properties(); prop.load(in); assertEquals("value1", prop.get("prop1")); assertEquals("value2", prop.get("prop2")); } Greeting, Joanna Jółkowska OPEGIEKA Sp. z o.o., al. Tysiąclecia 11, 82-300 Elbląg, www.opegieka.pl Bank Millennium S.A., PL: 84 1160 2202 0000 0000 6191 2549, EUR: PL 71 1160 2202 0000 5296 6311, SWIFT CODE: BIGBPLPW. Sąd Rejonowy w Olsztynie, VIII Wydział Gospodarczy Krajowego Rejestru Sądowego, KRS 0000190471, NIP 5780004498, REGON 001364260. Kapitał zakładowy/wpłacony 101 000 PLN.
_______________________________________________ Geoserver-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/geoserver-devel
