Opened 16 years ago
Closed 16 years ago
#2936 closed defect (fixed)
java.lang.NullPointerException on photo import
Reported by: | Owned by: | team | |
---|---|---|---|
Priority: | major | Milestone: | |
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)
Change History (8)
comment:1 by , 16 years ago
comment:2 by , 16 years ago
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 by , 16 years ago
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.
by , 16 years ago
Attachment: | image-load.patch added |
---|
comment:4 by , 16 years ago
There is another solution:
MapFrame frame = Main.map; if (frame != null) { frame.mapView.repaint() }
comment:5 by , 16 years ago
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 by , 16 years ago
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.
Could you attach the photo? With my photos I do not get this error.