#22898 closed defect (fixed)
[Patch] JOSM Validator CLI errors out when is run with --load-preferences argument
Reported by: | Owned by: | team | |
---|---|---|---|
Priority: | normal | Milestone: | 23.04 |
Component: | Core | Version: | latest |
Keywords: | Cc: |
Description (last modified by )
Use case: would like to use --load-preferences argument to add custom mapcss rules for the validator when running in CLI mode.
Problem: When running with --load-preferences, JOSM Validator CLI errors out.
Description:
I notice the issue is coming from these lines:
Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance());
- should be called before
this.parseArguments(argArray);
- should be called before
tempPreferences.getAllSettings().entrySet().stream().filter(entry -> entry.getValue().isNew())
- I removed the isNew filter because I noticed that they were not set to true.
The following code snippet is the git diff for the fix that I applied to mitigate this error. Note: I have little knowledge to the whole source code and this is my first time debugging and exploring the code myself.
-
src/org/openstreetmap/josm/data/validation/ValidatorCLI.java
diff --git a/src/org/openstreetmap/josm/data/validation/ValidatorCLI.java b/src/org/openstreetmap/josm/data/validation/ValidatorCLI.java index cd4164c37..a2807cfe5 100644
a b public class ValidatorCLI implements CLIModule { 165 165 // Ensure that preferences are only in memory 166 166 Config.setPreferencesInstance(new MemoryPreferences()); 167 167 Logging.setLogLevel(Level.INFO); 168 Logging.setLogLevel(this.logLevel); 169 HttpClient.setFactory(Http1Client::new); 170 Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance()); // for right-left-hand traffic cache file 171 Config.setUrlsProvider(JosmUrls.getInstance()); 172 ProjectionRegistry.setProjection(Projections.getProjectionByCode("epsg:3857".toUpperCase(Locale.ROOT))); 173 168 174 this.parseArguments(argArray); 169 175 if (this.input.isEmpty()) { 170 176 throw new IllegalArgumentException(tr("Missing argument - input data file ({0})", "--input|-i")); 171 177 } 178 172 179 this.initialize(); 173 180 final ProgressMonitor fileMonitor = progressMonitorFactory.get(); 174 181 fileMonitor.beginTask(tr("Processing files..."), this.input.size()); … … public class ValidatorCLI implements CLIModule { 345 352 * Arguments may need to be parsed first. 346 353 */ 347 354 void initialize() { 348 Logging.setLogLevel(this.logLevel);349 HttpClient.setFactory(Http1Client::new);350 Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance()); // for right-left-hand traffic cache file351 Config.setUrlsProvider(JosmUrls.getInstance());352 ProjectionRegistry.setProjection(Projections.getProjectionByCode("epsg:3857".toUpperCase(Locale.ROOT)));353 354 355 Territories.initializeInternalData(); 355 356 OsmValidator.initialize(); 356 357 MapPaintStyles.readFromPreferences(); … … public class ValidatorCLI implements CLIModule { 430 431 final IPreferences pref = Config.getPref(); 431 432 if (pref instanceof MemoryPreferences) { 432 433 final MemoryPreferences memoryPreferences = (MemoryPreferences) pref; 433 tempPreferences.getAllSettings().entrySet().stream() .filter(entry -> entry.getValue().isNew())434 tempPreferences.getAllSettings().entrySet().stream() 434 435 .forEach(entry -> memoryPreferences.putSetting(entry.getKey(), entry.getValue())); 435 436 } else { 436 437 throw new JosmRuntimeException(tr("Preferences are not the expected type"));
Attachments (1)
Change History (8)
comment:1 by , 23 months ago
Component: | Core validator → Core |
---|---|
Description: | modified (diff) |
Summary: | JOSM Validator CLI errors out when is run with --load-preferences argument → [Patch] JOSM Validator CLI errors out when is run with --load-preferences argument |
comment:2 by , 23 months ago
comment:3 by , 23 months ago
Milestone: | → 23.04 |
---|
comment:4 by , 23 months ago
Do you have a preference for how you will be given credit?
The commit message will look something like the following:
@taylor.smock: not really, the commit message looks good to me. thank you.
comment:6 by , 23 months ago
I still got this error when running the validator CLI (using josm-latest.jar with version 18715)
java.lang.NullPointerException: Cannot invoke "org.openstreetmap.josm.spi.preferences.IBaseDirectories.getPreferencesDirectory(boolean)" because the return value of "org.openstreetmap.josm.spi.preferences.Config.getDirs()" is null at org.openstreetmap.josm.gui.io.CustomConfigurator$XMLCommandProcessor.<init>(CustomConfigurator.java:415) at org.openstreetmap.josm.data.validation.ValidatorCLI.handleOption(ValidatorCLI.java:424) at org.openstreetmap.josm.data.validation.ValidatorCLI.lambda$parseArguments$8(ValidatorCLI.java:372) at org.openstreetmap.josm.tools.OptionParser$1.runFor(OptionParser.java:103) at org.openstreetmap.josm.tools.OptionParser.parseOptions(OptionParser.java:198) at org.openstreetmap.josm.tools.OptionParser.parseOptionsOrExit(OptionParser.java:116) at org.openstreetmap.josm.data.validation.ValidatorCLI.parseArguments(ValidatorCLI.java:380) at org.openstreetmap.josm.data.validation.ValidatorCLI.processArguments(ValidatorCLI.java:168) at org.openstreetmap.josm.gui.MainApplication.main(MainApplication.java:736)
This is how I run the validate command:
java -jar josm-latest.jar validate --load-preferences custom_josm_preferences.xml --input file.osm
@emanuel_raymond: Do you have a preference for how you will be given credit?
The commit message will look something like the following: