Modify

Opened 4 years ago

Closed 4 years ago

#2936 closed defect (fixed)

java.lang.NullPointerException on photo import

Reported by: Chris Bainbridge <chris.bainbridge@…> Owned by: team
Priority: major Component: Core
Version: latest Keywords:
Cc:

Description

This is with josm-r1779:

Uncaught error fetching image:
java.lang.NullPointerException

at org.openstreetmap.josm.gui.layer.GeoImageLayer$ImageEntry.imageLoaded(GeoImageLayer.java:267)
at org.openstreetmap.josm.gui.layer.GeoImageLayer$ImageLoader.finishImage(GeoImageLayer.java:183)
at org.openstreetmap.josm.gui.layer.GeoImageLayer$ImageLoader.imageUpdate(GeoImageLayer.java:228)
at sun.awt.image.ImageWatched$WeakLink.newInfo(ImageWatched.java:114)
at sun.awt.image.ImageWatched.newInfo(ImageWatched.java:151)
at sun.awt.image.ImageRepresentation.imageComplete(ImageRepresentation.java:639)
at sun.awt.image.ImageDecoder.imageComplete(ImageDecoder.java:135)
at sun.awt.image.JPEGImageDecoder.produceImage(JPEGImageDecoder.java:121)
at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:246)
at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:172)
at sun.awt.image.ImageFetcher.run(ImageFetcher.java:136)

Attachments (1)

image-load.patch (560 bytes) - added by plaicy 4 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 4 years ago by plaicy

Could you attach the photo? With my photos I do not get this error.

comment:2 Changed 4 years ago by jttt

It fails on Main.map.mapView.repaint(). That is really incorrect because image are loaded asynchronously and MapView might be removed before all images are loaded.

comment:3 Changed 4 years ago by plaicy

Okay. The 98% solution would be to check for null (I add a patch). The 99% solution would use java.util.concurrent.atomic.AtomicReference for Main.map and Main.map.mapView. The 100% must check if Main.map.mapView allows concurrent access and maybe block or a queue or something like that.

Changed 4 years ago by plaicy

comment:4 Changed 4 years ago by jttt

There is another solution:

MapFrame frame = Main.map;
if (frame != null) {
  frame.mapView.repaint()
}

comment:5 Changed 4 years ago by plaicy

I did not know reading and writing to references is in Java atomic: http://java.sun.com/docs/books/jls/third_edition/html/memory.html#17.7

So, iIf Main.map.mapView is granted to be non-null this is better.

In C this is not granted...

comment:6 Changed 4 years ago by jttt

Reading and writing of references is atomic. The link is about 8 byte variables while reference has only 4 bytes (even on 64b machine, reference is not the same thing as pointer).

If reading of references wasn't atomic then it would be possible to have invalid reference (first half comes from one thread, second from another thread). Fortuanatelly this can never happen.

comment:7 Changed 4 years ago by jttt

  • Resolution set to fixed
  • Status changed from new to closed

Fixed in r1863

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed .
as The resolution will be set. Next status will be 'closed'.
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.