Ticket #1636: 0001-Fix-NPE-when-invoking-JOSM-with-arg-help.patch

File 0001-Fix-NPE-when-invoking-JOSM-with-arg-help.patch, 5.5 KB (added by anonymous, 18 years ago)
  • src/org/openstreetmap/josm/gui/MainApplication.java

    From da559c821dc63c243051d39d8410bec551b4168f Mon Sep 17 00:00:00 2001
    From: Michel Marti <mcdmx@users.sf.net>
    Date: Mon, 6 Oct 2008 11:22:48 +0200
    Subject: [PATCH] Fix NPE when invoking JOSM with arg '--help'.
    
    Handle '--help', '-?' and '-h' arguments early so that there is no
    need for conditionally creating a splash screen (which later leads to
    a NullPointerException in case of '--help').
    
    Signed-off-by: Michel Marti <mcdmx@users.sf.net>
    ---
    Patch against SVN r1030.
    
    BTW: Has anyone looked at the results from running 'findbugs'
    (http://findbugs.sf.net/) against JOSM? Maybe it would be worth 'fixing'
    some of the stuff it complains about?
    
     .../openstreetmap/josm/gui/MainApplication.java    |   61 +++++++++-----------
     1 files changed, 27 insertions(+), 34 deletions(-)
    
    diff --git a/src/org/openstreetmap/josm/gui/MainApplication.java b/src/org/openstreetmap/josm/gui/MainApplication.java
    index 0403de2..050d079 100644
    a b public class MainApplication extends Main {  
    9191                        args.put(key, v);
    9292                }
    9393
    94                 // Only show the splash screen if we don't print the help and exit
    95                 SplashScreen splash;
    96                 if (!argList.contains("--help") && !argList.contains("-?") && !argList.contains("-h")) {
    97                         splash = new SplashScreen();
    98                 } else {
    99                         splash = null;
     94                if (argList.contains("--help") || argList.contains("-?") || argList.contains("-h")) {
     95                        // TODO: put in a platformHook for system that have no console by default
     96                        System.out.println(tr("Java OpenStreetMap Editor")+"\n\n"+
     97                                        tr("usage")+":\n"+
     98                                        "\tjava -jar josm.jar <option> <option> <option>...\n\n"+
     99                                        tr("options")+":\n"+
     100                                        "\t--help|-?|-h                              "+tr("Show this help")+"\n"+
     101                                        "\t--geometry=widthxheight(+|-)x(+|-)y       "+tr("Standard unix geometry argument")+"\n"+
     102                                        "\t[--download=]minlat,minlon,maxlat,maxlon  "+tr("Download the bounding box")+"\n"+
     103                                        "\t[--download=]<url>                        "+tr("Download the location at the url (with lat=x&lon=y&zoom=z)")+"\n"+
     104                                        "\t[--download=]<filename>                   "+tr("Open file (as raw gps, if .gpx)")+"\n"+
     105                                        "\t--downloadgps=minlat,minlon,maxlat,maxlon "+tr("Download the bounding box as raw gps")+"\n"+
     106                                        "\t--selection=<searchstring>                "+tr("Select with the given search")+"\n"+
     107                                        "\t--no-fullscreen                           "+tr("Don't launch in fullscreen mode")+"\n"+
     108                                        "\t--reset-preferences                       "+tr("Reset the preferences to default")+"\n\n"+
     109                                        "\t--language=<language>                     "+tr("Set the language.")+"\n\n"+
     110                                        tr("examples")+":\n"+
     111                                        "\tjava -jar josm.jar track1.gpx track2.gpx london.osm\n"+
     112                                        "\tjava -jar josm.jar http://www.openstreetmap.org/index.html?lat=43.2&lon=11.1&zoom=13\n"+
     113                                        "\tjava -jar josm.jar london.osm --selection=http://www.ostertag.name/osm/OSM_errors_node-duplicate.xml\n"+
     114                                        "\tjava -jar josm.jar 43.2,11.1,43.4,11.4\n\n"+
     115
     116                                        tr("Parameters are read in the order they are specified, so make sure you load\n"+
     117                                        "some data before --selection")+"\n\n"+
     118                                        tr("Instead of --download=<bbox> you may specify osm://<bbox>\n"));
     119                        System.exit(0);
    100120                }
    101121
     122                SplashScreen splash = new SplashScreen();
    102123                splash.setStatus(tr("Reading preferences"));
    103124                // get the preferences.
    104125                final File prefDir = new File(Main.pref.getPreferencesDir());
    public class MainApplication extends Main {  
    152173                splash.setStatus(tr("Loading early plugins"));
    153174                Main.loadPlugins(true, language);
    154175
    155                 if (argList.contains("--help") || argList.contains("-?") || argList.contains("-h")) {
    156                         // TODO: put in a platformHook for system that have no console by default
    157                         System.out.println(tr("Java OpenStreetMap Editor")+"\n\n"+
    158                                         tr("usage")+":\n"+
    159                                         "\tjava -jar josm.jar <option> <option> <option>...\n\n"+
    160                                         tr("options")+":\n"+
    161                                         "\t--help|-?|-h                              "+tr("Show this help")+"\n"+
    162                                         "\t--geometry=widthxheight(+|-)x(+|-)y       "+tr("Standard unix geometry argument")+"\n"+
    163                                         "\t[--download=]minlat,minlon,maxlat,maxlon  "+tr("Download the bounding box")+"\n"+
    164                                         "\t[--download=]<url>                        "+tr("Download the location at the url (with lat=x&lon=y&zoom=z)")+"\n"+
    165                                         "\t[--download=]<filename>                   "+tr("Open file (as raw gps, if .gpx)")+"\n"+
    166                                         "\t--downloadgps=minlat,minlon,maxlat,maxlon "+tr("Download the bounding box as raw gps")+"\n"+
    167                                         "\t--selection=<searchstring>                "+tr("Select with the given search")+"\n"+
    168                                         "\t--no-fullscreen                           "+tr("Don't launch in fullscreen mode")+"\n"+
    169                                         "\t--reset-preferences                       "+tr("Reset the preferences to default")+"\n\n"+
    170                                         "\t--language=<language>                     "+tr("Set the language.")+"\n\n"+
    171                                         tr("examples")+":\n"+
    172                                         "\tjava -jar josm.jar track1.gpx track2.gpx london.osm\n"+
    173                                         "\tjava -jar josm.jar http://www.openstreetmap.org/index.html?lat=43.2&lon=11.1&zoom=13\n"+
    174                                         "\tjava -jar josm.jar london.osm --selection=http://www.ostertag.name/osm/OSM_errors_node-duplicate.xml\n"+
    175                                         "\tjava -jar josm.jar 43.2,11.1,43.4,11.4\n\n"+
    176 
    177                                         tr("Parameters are read in the order they are specified, so make sure you load\n"+
    178                                         "some data before --selection")+"\n\n"+
    179                                         tr("Instead of --download=<bbox> you may specify osm://<bbox>\n"));
    180                         System.exit(0);
    181                 }
    182 
    183176                splash.setStatus(tr("Setting defaults"));
    184177                preConstructorInit(args);
    185178                splash.setStatus(tr("Creating main GUI"));