Changeset 7476 in josm


Ignore:
Timestamp:
2014-08-31T13:30:38+02:00 (10 years ago)
Author:
Don-vip
Message:

fix NPE seen in continuous integration, reproducible in offline mode

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/Main.java

    r7442 r7476  
    548548        List<Callable<Void>> tasks = new ArrayList<>();
    549549
    550         if (isOffline(OnlineResource.OSM_API)) {
    551             Main.warn(tr("{0} not available (offline mode)", tr("OSM API")));
    552         } else {
    553             tasks.add(new InitializationTask(tr("Initializing OSM API")) {
    554 
    555                 @Override
    556                 public void initialize() throws Exception {
    557                     // We try to establish an API connection early, so that any API
    558                     // capabilities are already known to the editor instance. However
    559                     // if it goes wrong that's not critical at this stage.
    560                     try {
    561                         OsmApi.getOsmApi().initialize(null, true);
    562                     } catch (Exception e) {
    563                         Main.warn(getErrorMessage(Utils.getRootCause(e)));
    564                     }
     550        tasks.add(new InitializationTask(tr("Initializing OSM API")) {
     551
     552            @Override
     553            public void initialize() throws Exception {
     554                // We try to establish an API connection early, so that any API
     555                // capabilities are already known to the editor instance. However
     556                // if it goes wrong that's not critical at this stage.
     557                try {
     558                    OsmApi.getOsmApi().initialize(null, true);
     559                } catch (Exception e) {
     560                    Main.warn(getErrorMessage(Utils.getRootCause(e)));
    565561                }
    566             });
    567         }
     562            }
     563        });
    568564
    569565        tasks.add(new InitializationTask(tr("Initializing validator")) {
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java

    r7203 r7476  
    2424import org.openstreetmap.josm.data.Bounds;
    2525import org.openstreetmap.josm.data.Preferences.pref;
     26import org.openstreetmap.josm.io.Capabilities;
    2627import org.openstreetmap.josm.io.OsmApi;
    2728import org.openstreetmap.josm.tools.CheckParameterUtil;
     
    148149        }
    149150    }
    150    
     151
    151152    /** name of the imagery entry (gets translated by josm usually) */
    152153    private String name;
     
    393394        return true;
    394395    }
    395    
     396
    396397    /**
    397398     * Check if this object equals another ImageryInfo with respect to the properties
    398399     * that get written to the preference file.
    399      * 
     400     *
    400401     * The field {@link #pixelPerDegree} is ignored.
    401      * 
     402     *
    402403     * @param other the ImageryInfo object to compare to
    403404     * @return true if they are equal
     
    464465    }
    465466
    466    
     467
    467468    @Override
    468469    public int hashCode() {
     
    679680    /**
    680681     * Gets the entry id.
    681      * 
     682     *
    682683     * Id can be null. This gets the configured id as is. Due to a user error,
    683684     * this may not be unique. Use {@link ImageryLayerInfo#getUniqueId} to ensure
     
    696697        this.id = id;
    697698    }
    698    
     699
    699700    public void clearId() {
    700701        if (this.id != null) {
     
    934935     */
    935936    public boolean isBlacklisted() {
    936         return OsmApi.getOsmApi().getCapabilities().isOnImageryBlacklist(this.url);
     937        Capabilities capabilities = OsmApi.getOsmApi().getCapabilities();
     938        return capabilities != null && capabilities.isOnImageryBlacklist(this.url);
    937939    }
    938940}
  • trunk/src/org/openstreetmap/josm/io/OsmApi.java

    r7473 r7476  
    203203        if (initialized)
    204204            return;
    205         if (Main.isOffline(OnlineResource.OSM_API)) {
    206             // At this point this is an error because all automatic or UI actions requiring OSM API should have been disabled earlier
    207             throw new OfflineAccessException(tr("{0} not available (offline mode)", OnlineResource.OSM_API.getLocName()));
    208         }
    209205        cancel = false;
    210206        try {
     
    217213                initializeCapabilities(cache.updateForceString());
    218214            }
    219             if (capabilities.supportsVersion("0.6")) {
    220                 version = "0.6";
    221             } else {
     215            if (capabilities == null) {
     216                if (Main.isOffline(OnlineResource.OSM_API)) {
     217                    Main.warn(tr("{0} not available (offline mode)", tr("OSM API")));
     218                } else {
     219                    Main.error(tr("Unable to initialize OSM API."));
     220                }
     221                return;
     222            } else if (!capabilities.supportsVersion("0.6")) {
    222223                Main.error(tr("This version of JOSM is incompatible with the configured server."));
    223224                Main.error(tr("It supports protocol version 0.6, while the server says it supports {0} to {1}.",
    224225                        capabilities.get("version", "minimum"), capabilities.get("version", "maximum")));
    225                 initialized = false; // FIXME gets overridden by next assignment
     226                return;
     227            } else {
     228                version = "0.6";
     229                initialized = true;
    226230            }
    227             initialized = true;
    228231
    229232            /* This is an interim solution for openstreetmap.org not currently
     
    233236             * http://trac.openstreetmap.org/ticket/5024
    234237             * This list should not be maintained by each OSM editor (see #9210) */
    235             if (this.serverUrl.matches(".*openstreetmap.org/api.*") && capabilities.getImageryBlacklist().isEmpty())
    236             {
     238            if (this.serverUrl.matches(".*openstreetmap.org/api.*") && capabilities.getImageryBlacklist().isEmpty()) {
    237239                capabilities.put("blacklist", "regex", ".*\\.google\\.com/.*");
    238240                capabilities.put("blacklist", "regex", ".*209\\.85\\.2\\d\\d.*");
     
    245247             * situation - probably only occurs if the user changes the API URL
    246248             * in the preferences menu. Otherwise they would not have been able
    247              * to load the layers in the first place becuase they would have
     249             * to load the layers in the first place because they would have
    248250             * been disabled! */
    249251            if (Main.isDisplayingMapView()) {
     
    268270    }
    269271
    270     private void initializeCapabilities(String xml) throws SAXException, IOException, ParserConfigurationException {
    271         capabilities = CapabilitiesParser.parse(new InputSource(new StringReader(xml)));
     272    private synchronized void initializeCapabilities(String xml) throws SAXException, IOException, ParserConfigurationException {
     273        if (xml != null) {
     274            capabilities = CapabilitiesParser.parse(new InputSource(new StringReader(xml)));
     275        }
    272276    }
    273277
     
    731735     * @return the API capabilities, or null, if the API is not initialized yet
    732736     */
    733     public Capabilities getCapabilities() {
     737    public synchronized Capabilities getCapabilities() {
    734738        return capabilities;
    735739    }
Note: See TracChangeset for help on using the changeset viewer.