Modify

Opened 23 months ago

Closed 23 months ago

Last modified 23 months ago

#22898 closed defect (fixed)

[Patch] JOSM Validator CLI errors out when is run with --load-preferences argument

Reported by: emanuel_raymond@… Owned by: team
Priority: normal Milestone: 23.04
Component: Core Version: latest
Keywords: Cc:

Description (last modified by skyper)

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);
  • 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 {  
    165165            // Ensure that preferences are only in memory
    166166            Config.setPreferencesInstance(new MemoryPreferences());
    167167            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           
    168174            this.parseArguments(argArray);
    169175            if (this.input.isEmpty()) {
    170176                throw new IllegalArgumentException(tr("Missing argument - input data file ({0})", "--input|-i"));
    171177            }
     178           
    172179            this.initialize();
    173180            final ProgressMonitor fileMonitor = progressMonitorFactory.get();
    174181            fileMonitor.beginTask(tr("Processing files..."), this.input.size());
    public class ValidatorCLI implements CLIModule {  
    345352     * Arguments may need to be parsed first.
    346353     */
    347354    void initialize() {
    348         Logging.setLogLevel(this.logLevel);
    349         HttpClient.setFactory(Http1Client::new);
    350         Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance()); // for right-left-hand traffic cache file
    351         Config.setUrlsProvider(JosmUrls.getInstance());
    352         ProjectionRegistry.setProjection(Projections.getProjectionByCode("epsg:3857".toUpperCase(Locale.ROOT)));
    353 
    354355        Territories.initializeInternalData();
    355356        OsmValidator.initialize();
    356357        MapPaintStyles.readFromPreferences();
    public class ValidatorCLI implements CLIModule {  
    430431            final IPreferences pref = Config.getPref();
    431432            if (pref instanceof MemoryPreferences) {
    432433                final MemoryPreferences memoryPreferences = (MemoryPreferences) pref;
    433                 tempPreferences.getAllSettings().entrySet().stream().filter(entry -> entry.getValue().isNew())
     434                tempPreferences.getAllSettings().entrySet().stream()
    434435                        .forEach(entry -> memoryPreferences.putSetting(entry.getKey(), entry.getValue()));
    435436            } else {
    436437                throw new JosmRuntimeException(tr("Preferences are not the expected type"));

Attachments (1)

22898.patch (3.7 KB ) - added by taylor.smock 23 months ago.
Add non-regression test, simplify original patch

Download all attachments as: .zip

Change History (8)

comment:1 by skyper, 23 months ago

Component: Core validatorCore
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 taylor.smock, 23 months ago

@emanuel_raymond: Do you have a preference for how you will be given credit?

The commit message will look something like the following:

Fix #22898: JOSM Validator CLI errors out when is run with --load-preferences argument (patch by emanuel_raymond)

comment:3 by taylor.smock, 23 months ago

Milestone: 23.04

by taylor.smock, 23 months ago

Attachment: 22898.patch added

Add non-regression test, simplify original patch

comment:4 by emanuel_raymond@…, 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:5 by taylor.smock, 23 months ago

Resolution: fixed
Status: newclosed

In 18714/josm:

Fix #22898: JOSM Validator CLI errors out when is run with --load-preferences argument (patch by emanuel_raymond, modified)

comment:6 by emanuel_raymond@…, 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

comment:7 by taylor.smock, 23 months ago

In 18718/josm:

See #22898: JOSM Validator CLI errors out when is run with --load-preferences argument

There was an additional problem related to the directories setup order.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.