Changeset 31427 in osm


Ignore:
Timestamp:
2015-08-01T18:19:40+02:00 (9 years ago)
Author:
wiktorn
Message:

Coverity detected fixes:

TileSourceInfo:

  • Initialize cookies variable in Tile

BingAerialTileSource:

  • make Attribution class static

CheckBoxTree:

  • change Boolean instance comparision with equals()

MemoryTileCache:

  • fix synchronization issues, remove unused methods

MapObjectImpl

  • fix null pointer dereference

LayerGroup:

  • fix unboxing and immediatly boxing Boolean value
  • fix null pointer dereference

JobDispatcher:

  • synchronize access to workerThreadCount and use equals when comparing tiles

Tile:

  • use TileSource of the Tile in equals(...)

Coordinate:

  • remove implements Serializable - no fields are stored anyway

JMapViewer:

  • fix for null pointer dereference, make TileSource transient as it is not serializable anyway
Location:
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Coordinate.java

    r30900 r31427  
    66import java.io.ObjectInputStream;
    77import java.io.ObjectOutputStream;
    8 import java.io.Serializable;
    98import java.util.Objects;
    109
     
    1817 *
    1918 */
    20 public class Coordinate implements Serializable, ICoordinate {
     19public class Coordinate implements ICoordinate {
    2120    private transient Point2D.Double data;
    2221
     
    5251    }
    5352
     53    @Override
    5454    public String toString() {
    5555        return "Coordinate[" + data.y + ", " + data.x + "]";
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java

    r31310 r31427  
    8989    protected ZOOM_BUTTON_STYLE zoomButtonStyle;
    9090
    91     protected TileSource tileSource;
     91    protected transient TileSource tileSource;
    9292
    9393    protected AttributionSupport attribution = new AttributionSupport();
     
    263263        int mapZoomMax = tileController.getTileSource().getMaxZoom();
    264264
    265         if (markers) {
     265        if (markers && mapMarkerList != null) {
    266266            synchronized (mapMarkerList) {
    267267                for (MapMarker marker : mapMarkerList) {
     
    277277        }
    278278
    279         if (rectangles) {
     279        if (rectangles && mapRectangleList != null) {
    280280            synchronized (mapRectangleList) {
    281281                for (MapRectangle rectangle : mapRectangleList) {
     
    292292        }
    293293
    294         if (polygons) {
     294        if (polygons && mapPolygonList != null) {
    295295            synchronized (mapPolygonList) {
    296296                for (MapPolygon polygon : mapPolygonList) {
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewerTree.java

    r30900 r31427  
    4141        super();
    4242        splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    43        
     43
    4444        tree = new CheckBoxTree(name);
    4545        treePanel = new JPanel();
     
    5151        splitPane.setOneTouchExpandable(true);
    5252        splitPane.setDividerLocation(150);
    53        
     53
    5454        //Provide minimum sizes for the two components in the split pane
    5555        Dimension minimumSize = new Dimension(100, 50);
     
    6060        setTreeVisible(treeVisible);
    6161        tree.addNodeListener(new MouseAdapter() {
     62            @Override
    6263            public void mousePressed(MouseEvent e) {
    6364                maybeShowPopup(e);
    6465            }
     66            @Override
    6567            public void mouseReleased(MouseEvent e) {
    6668                maybeShowPopup(e);
     
    6870            private void maybeShowPopup(MouseEvent e) {
    6971                if (e.isPopupTrigger()) {
    70                     e.getSource();
    7172                    AbstractLayer layer = ((CheckBoxNodePanel)e.getComponent()).getData().getAbstractLayer();
    7273                    if(layer!=null)
     
    7980        JMenuItem menuItemShow = new JMenuItem("show texts");
    8081        JMenuItem menuItemHide = new JMenuItem("hide texts");
    81  
     82
    8283        //Create the popup menu.
    8384        JPopupMenu popup = new JPopupMenu();
    84        
     85
    8586        // Create items
    8687        if(layer.isVisibleTexts()==null){
     
    8990        }else if(layer.isVisibleTexts()) popup.add(menuItemHide);
    9091        else popup.add(menuItemShow);
    91        
     92
    9293        menuItemShow.addActionListener(new ActionListener(){
    9394            @Override
     
    106107            }
    107108        });
    108  
     109
    109110        return popup;
    110111    }
     
    143144    }
    144145    public void addMapObject(MapObject o){
    145        
     146
    146147    }
    147148    public void setTreeVisible(boolean visible){
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JobDispatcher.java

    r30900 r31427  
    9898            if(job.getTile() != null) {
    9999                for(TileJob oldJob : jobQueue) {
    100                     if(oldJob.getTile() == job.getTile()) {
     100                    if (job.getTile().equals(oldJob.getTile())) {
    101101                        return;
    102102                    }
     
    104104            }
    105105            jobQueue.put(job);
    106             if (workerThreadIdleCount == 0 && workerThreadCount < workerThreadMaxCount)
    107                 addWorkerThread();
     106            synchronized (this) {
     107                if (workerThreadIdleCount == 0 && workerThreadCount < workerThreadMaxCount)
     108                    addWorkerThread();
     109            }
    108110        } catch (InterruptedException e) {
    109111        }
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/LayerGroup.java

    r30900 r31427  
    66public class LayerGroup extends AbstractLayer{
    77    private List<AbstractLayer> layers;
    8    
     8
    99    public LayerGroup(String name){
    1010        super(name);
     
    4141        return this;
    4242    }
    43     public void calculateVisibleTexts(){
     43    public void calculateVisibleTexts() {
    4444        Boolean calculate=null;
    45         if(layers!=null&&layers.size()>0){
     45        if (layers!=null&&layers.size()>0){
    4646            calculate=layers.get(0).isVisibleTexts();
    47             for(int i=1;i<layers.size(); i++){
     47            for (int i=1;i<layers.size(); i++){
    4848                calculate = resultOf(calculate, layers.get(i).isVisibleTexts());
    4949            }
     
    5252        if(getParent()!=null) getParent().calculateVisibleTexts();
    5353    }
    54     public Boolean resultOf(Boolean b1, Boolean b2){
    55         if(b1==null||b2==null) return null;
    56         else if(b1.booleanValue() == b2.booleanValue()) return b1.booleanValue();
    57         else return null;
     54    public Boolean resultOf(Boolean b1, Boolean b2) {
     55        if (b1 != null && b1.equals(b2)) {
     56            return b1;
     57        }
     58        return Boolean.FALSE;
    5859    }
    5960}
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/MapObjectImpl.java

    r30900 r31427  
    6969        if(style!=null) style.setStroke(stroke);
    7070    }
    71    
     71
    7272    public Font getFont() {
    7373        Style styleAssigned = getStyleAssigned();
     
    9595    public static Font getDefaultFont(){
    9696        Font f = UIManager.getDefaults().getFont("TextField.font");
     97        if (f == null) {
     98            f = Font.decode(null);
     99        }
    97100        return new Font(f.getName(), Font.BOLD, f.getSize());
    98101    }
     102
    99103    public void paintText(Graphics g, Point position) {
    100104        if(name!=null && g!=null && position!=null){
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/MemoryTileCache.java

    r30900 r31427  
    9191
    9292    @Override
    93     public int getTileCount() {
     93    public synchronized int getTileCount() {
    9494        return hash.size();
    9595    }
    9696
    97     public int getCacheSize() {
     97    public synchronized int getCacheSize() {
    9898        return cacheSize;
    9999    }
     
    117117    protected static class CacheEntry {
    118118        Tile tile;
    119 
    120119        CacheEntry next;
    121120        CacheEntry prev;
     
    124123            this.tile = tile;
    125124        }
    126 
    127         public Tile getTile() {
    128             return tile;
    129         }
    130 
    131         public CacheEntry getNext() {
    132             return next;
    133         }
    134 
    135         public CacheEntry getPrev() {
    136             return prev;
    137         }
    138 
    139125    }
    140126
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Tile.java

    r31143 r31427  
    278278        if (zoom != other.zoom)
    279279            return false;
     280        if (!getTileSource().equals(other.getTileSource())) {
     281            return false;
     282        }
    280283        return true;
    281284    }
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/checkBoxTree/CheckBoxTree.java

    r30900 r31427  
    2121/**
    2222 * JTree for checkBox Tree Layers
    23  * 
     23 *
    2424 * @author galo
    2525 */
     
    2727    /** Serial Version UID */
    2828    private static final long serialVersionUID = 6943401106938034256L;
    29    
     29
    3030    private final CheckBoxNodeEditor editor;
    3131
     
    4848        setCellEditor(editor);
    4949        setEditable(true);
    50        
     50
    5151        // listen for changes in the model (including check box toggles)
    5252        getModel().addTreeModelListener(new TreeModelListener() {
     
    121121    private static Boolean childStatus(DefaultMutableTreeNode node){
    122122        Boolean status = data(node.getChildAt(0)).isSelected();
    123         for(int i=1; i<node.getChildCount()&&status!=null; i++){
    124             if(status != data(node.getChildAt(i)).isSelected()) return null;
     123        for (int i=1; i<node.getChildCount() && status!=null; i++){
     124            if (!status.equals(
     125                    data(node.getChildAt(i)).isSelected()
     126                    ))
     127                return null;
    125128        }
    126129        return status;
     
    132135                CheckBoxNodeData dataParent = data(parent);
    133136                Boolean childStatus = childStatus(parent);
    134                 if(dataParent.isSelected()!=childStatus){
     137                if(childStatus != null && !childStatus.equals(dataParent.isSelected())) {
    135138                    dataParent.setSelected(childStatus);
    136139                    changeParents(parent);
     
    148151        for(int i=0; i<node.getChildCount(); i++){
    149152            DefaultMutableTreeNode childNode = node(node.getChildAt(i));
    150             if (data(childNode).isSelected() !=data(node).isSelected()){
     153            if (!data(childNode).isSelected().equals(data(node).isSelected())){
    151154                data(childNode).setSelected(data(node).isSelected());
    152155                setChildrens(childNode, value);
     
    216219    public DefaultMutableTreeNode add(DefaultMutableTreeNode parent, final AbstractLayer layer){
    217220        layer.setVisible(data(parent).isSelected());
    218         DefaultMutableTreeNode node = createNode(layer); 
     221        DefaultMutableTreeNode node = createNode(layer);
    219222        parent.add(node);
    220223        ((DefaultTreeModel)getModel()).reload();
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/BingAerialTileSource.java

    r31301 r31427  
    6161    }
    6262
    63     protected class Attribution {
     63    protected static class Attribution {
    6464        String attribution;
    6565        int minZoom;
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TileSourceInfo.java

    r31301 r31427  
    3030
    3131    /** cookies that needs to be sent to tile source */
    32     protected String cookies;
     32    protected String cookies = "";
    3333
    3434    /** tile size of the displayed tiles */
Note: See TracChangeset for help on using the changeset viewer.