Ticket #13190: patch-bug-report-add-more-reports.patch

File patch-bug-report-add-more-reports.patch, 9.5 KB (added by michael2402, 8 years ago)
  • src/org/openstreetmap/josm/gui/MapView.java

    diff --git a/src/org/openstreetmap/josm/gui/MapView.java b/src/org/openstreetmap/josm/gui/MapView.java
    index da3079e..3f6a362 100644
    a b LayerManager.LayerChangeListener, MainLayerManager.ActiveLayerChangeListener {  
    919919
    920920        synchronized (temporaryLayers) {
    921921            for (MapViewPaintable mvp : temporaryLayers) {
    922                 mvp.paint(tempG, this, box);
     922                try {
     923                    mvp.paint(tempG, this, box);
     924                } catch (RuntimeException e) {
     925                    throw BugReport.intercept(e).put("mvp", mvp);
     926                }
    923927            }
    924928        }
    925929
    926930        // draw world borders
     931        try {
     932            drawWorldBorders(tempG);
     933        } catch (RuntimeException e) {
     934            throw BugReport.intercept(e).put("bounds", () -> getProjection().getWorldBoundsLatLon());
     935        }
     936
     937        if (Main.isDisplayingMapView() && Main.map.filterDialog != null) {
     938            Main.map.filterDialog.drawOSDText(tempG);
     939        }
     940
     941        if (playHeadMarker != null) {
     942            playHeadMarker.paint(tempG, this);
     943        }
     944
     945        try {
     946            g.drawImage(offscreenBuffer, 0, 0, null);
     947        } catch (ClassCastException e) {
     948            // See #11002 and duplicate tickets. On Linux with Java >= 8 Many users face this error here:
     949            //
     950            // java.lang.ClassCastException: sun.awt.image.BufImgSurfaceData cannot be cast to sun.java2d.xr.XRSurfaceData
     951            //   at sun.java2d.xr.XRPMBlitLoops.cacheToTmpSurface(XRPMBlitLoops.java:145)
     952            //   at sun.java2d.xr.XrSwToPMBlit.Blit(XRPMBlitLoops.java:353)
     953            //   at sun.java2d.pipe.DrawImage.blitSurfaceData(DrawImage.java:959)
     954            //   at sun.java2d.pipe.DrawImage.renderImageCopy(DrawImage.java:577)
     955            //   at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:67)
     956            //   at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:1014)
     957            //   at sun.java2d.pipe.ValidatePipe.copyImage(ValidatePipe.java:186)
     958            //   at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:3318)
     959            //   at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:3296)
     960            //   at org.openstreetmap.josm.gui.MapView.paint(MapView.java:834)
     961            //
     962            // It seems to be this JDK bug, but Oracle does not seem to be fixing it:
     963            // https://bugs.openjdk.java.net/browse/JDK-7172749
     964            //
     965            // According to bug reports it can happen for a variety of reasons such as:
     966            // - long period of time
     967            // - change of screen resolution
     968            // - addition/removal of a secondary monitor
     969            //
     970            // But the application seems to work fine after, so let's just log the error
     971            Main.error(e);
     972        }
     973        super.paint(g);
     974    }
     975
     976    private void drawWorldBorders(Graphics2D tempG) {
    927977        tempG.setColor(Color.WHITE);
    928978        Bounds b = getProjection().getWorldBoundsLatLon();
    929979        double lat = b.getMinLat();
    LayerManager.LayerChangeListener, MainLayerManager.ActiveLayerChangeListener {  
    9661016        final Area viewport = new Area(new Rectangle(-1, -1, w + 2, h + 2));
    9671017        border.intersect(viewport);
    9681018        tempG.draw(border);
    969 
    970         if (Main.isDisplayingMapView() && Main.map.filterDialog != null) {
    971             Main.map.filterDialog.drawOSDText(tempG);
    972         }
    973 
    974         if (playHeadMarker != null) {
    975             playHeadMarker.paint(tempG, this);
    976         }
    977 
    978         try {
    979             g.drawImage(offscreenBuffer, 0, 0, null);
    980         } catch (ClassCastException e) {
    981             // See #11002 and duplicate tickets. On Linux with Java >= 8 Many users face this error here:
    982             //
    983             // java.lang.ClassCastException: sun.awt.image.BufImgSurfaceData cannot be cast to sun.java2d.xr.XRSurfaceData
    984             //   at sun.java2d.xr.XRPMBlitLoops.cacheToTmpSurface(XRPMBlitLoops.java:145)
    985             //   at sun.java2d.xr.XrSwToPMBlit.Blit(XRPMBlitLoops.java:353)
    986             //   at sun.java2d.pipe.DrawImage.blitSurfaceData(DrawImage.java:959)
    987             //   at sun.java2d.pipe.DrawImage.renderImageCopy(DrawImage.java:577)
    988             //   at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:67)
    989             //   at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:1014)
    990             //   at sun.java2d.pipe.ValidatePipe.copyImage(ValidatePipe.java:186)
    991             //   at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:3318)
    992             //   at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:3296)
    993             //   at org.openstreetmap.josm.gui.MapView.paint(MapView.java:834)
    994             //
    995             // It seems to be this JDK bug, but Oracle does not seem to be fixing it:
    996             // https://bugs.openjdk.java.net/browse/JDK-7172749
    997             //
    998             // According to bug reports it can happen for a variety of reasons such as:
    999             // - long period of time
    1000             // - change of screen resolution
    1001             // - addition/removal of a secondary monitor
    1002             //
    1003             // But the application seems to work fine after, so let's just log the error
    1004             Main.error(e);
    1005         }
    1006         super.paint(g);
    10071019    }
    10081020
    10091021    /**
  • src/org/openstreetmap/josm/gui/MapViewState.java

    diff --git a/src/org/openstreetmap/josm/gui/MapViewState.java b/src/org/openstreetmap/josm/gui/MapViewState.java
    index 3167680..6202da0 100644
    a b import org.openstreetmap.josm.data.coor.EastNorth;  
    1717import org.openstreetmap.josm.data.coor.LatLon;
    1818import org.openstreetmap.josm.data.projection.Projection;
    1919import org.openstreetmap.josm.gui.download.DownloadDialog;
     20import org.openstreetmap.josm.tools.bugreport.BugReport;
    2021
    2122/**
    2223 * This class represents a state of the {@link MapView}.
    public final class MapViewState {  
    9697            topLeftInWindow.y += component.getY();
    9798            component = component.getParent();
    9899        }
    99         topLeftOnScreen = position.getLocationOnScreen();
     100        try {
     101            topLeftOnScreen = position.getLocationOnScreen();
     102        } catch (RuntimeException e) {
     103            throw BugReport.intercept(e).put("position", position).put("parent", () -> position.getParent());
     104        }
    100105    }
    101106
    102107    private MapViewState(Projection projection, MapViewState mapViewState) {
  • src/org/openstreetmap/josm/tools/bugreport/BugReport.java

    diff --git a/src/org/openstreetmap/josm/tools/bugreport/BugReport.java b/src/org/openstreetmap/josm/tools/bugreport/BugReport.java
    index f74af94..3bc055e 100644
    a b package org.openstreetmap.josm.tools.bugreport;  
    1313 * <p>
    1414 * You should then add some debug information there. This can be the OSM ids that caused the error, information on the data you were working on
    1515 * or other local variables. Make sure that no excpetions may occur while computing the values. It is best to send plain local variables to
    16  * put(...). Then simply throw the throwable you got from the bug report. The global exception handler will do the rest.
     16 * put(...). If you need to do computations, put them into a lambda expression. Then simply throw the throwable you got from the bug report.
     17 * The global exception handler will do the rest.
    1718 * <pre>
    1819 * int id = ...;
    1920 * String tag = "...";
    2021 * try {
    2122 *   ... your code ...
    2223 * } catch (Throwable t) {
    23  *   throw BugReport.intercept(t).put("id", id).put("tag", tag);
     24 *   throw BugReport.intercept(t).put("id", id).put("tag", () -> x.getTag());
    2425 * }
    2526 * </pre>
    2627 *
  • src/org/openstreetmap/josm/tools/bugreport/ReportedException.java

    diff --git a/src/org/openstreetmap/josm/tools/bugreport/ReportedException.java b/src/org/openstreetmap/josm/tools/bugreport/ReportedException.java
    index 1fe31ca..c0a79c5 100644
    a b import java.util.LinkedList;  
    1111import java.util.Map;
    1212import java.util.Map.Entry;
    1313import java.util.Set;
     14import java.util.function.Supplier;
    1415
    1516import org.openstreetmap.josm.Main;
    1617
    public class ReportedException extends RuntimeException {  
    173174    }
    174175
    175176    /**
    176      * Adds some debug values to this exception.
     177     * Adds some debug values to this exception. The value is converted to a string. Errors during conversion are handled.
    177178     *
    178179     * @param key
    179180     *            The key to add this for. Does not need to be unique but it would be nice.
    public class ReportedException extends RuntimeException {  
    182183     * @return This exception for easy chaining.
    183184     */
    184185    public ReportedException put(String key, Object value) {
     186        return put(key, () -> value);
     187    }
     188
     189    /**
     190     * Adds some debug values to this exception. This method automatically catches errors that occur during the production of the value.
     191     *
     192     * @param key
     193     *            The key to add this for. Does not need to be unique but it would be nice.
     194     * @param valueSupplier
     195     *            A supplier that is called once to get the value.
     196     * @return This exception for easy chaining.
     197     */
     198    public ReportedException put(String key, Supplier<Object> valueSupplier) {
    185199        String string;
    186200        try {
     201            Object value = valueSupplier.get();
    187202            if (value == null) {
    188203                string = "null";
    189204            } else if (value instanceof Collection) {