Program: 154015
Project: 154015
Buggy source:
/** 
 * Implementation of <code>PropertyChangeListener</code>. <p> When invoked with an event which is an instance of <code>RenderingChangeEvent</code> the node will respond by re-rendering itself while retaining any tiles possible.
 */
public synchronized void propertyChange(PropertyChangeEvent evt){
  Object evtSrc=evt.getSource();
  Vector nodeSources=nodeSupport.getParameterBlock().getSources();
  String propName=evt.getPropertyName().toLowerCase();
  if (theImage != null && ((evt instanceof PropertyChangeEventJAI && evtSrc == this && !(evt instanceof PropertySourceChangeEvent) && nodeEventNames.contains(propName)) || ((evt instanceof RenderingChangeEvent || evt instanceof CollectionChangeEvent || (evt instanceof PropertyChangeEventJAI && evtSrc instanceof RenderedImage && propName.equals("String_Node_Str"))) && nodeSources.contains(evtSrc)))) {
    PlanarImage theOldImage=theImage;
    boolean shouldFireEvent=false;
    Shape invalidRegion=null;
    if (evtSrc == this && (propName.equals("String_Node_Str") || propName.equals("String_Node_Str") || propName.equals("String_Node_Str"))) {
      shouldFireEvent=true;
      theImage=null;
    }
 else     if (evt instanceof RenderingChangeEvent || (evtSrc instanceof RenderedImage && propName.equals("String_Node_Str"))) {
      shouldFireEvent=true;
      Shape srcInvalidRegion=null;
      if (evt instanceof RenderingChangeEvent) {
        RenderingChangeEvent rcEvent=(RenderingChangeEvent)evt;
        srcInvalidRegion=rcEvent.getInvalidRegion();
        if (srcInvalidRegion == null) {
          srcInvalidRegion=((PlanarImage)rcEvent.getOldValue()).getBounds();
        }
      }
 else {
        srcInvalidRegion=(Shape)evt.getNewValue();
        if (srcInvalidRegion == null) {
          RenderedImage rSrc=(RenderedImage)evtSrc;
          srcInvalidRegion=new Rectangle(rSrc.getMinX(),rSrc.getMinY(),rSrc.getWidth(),rSrc.getHeight());
        }
      }
      if (!(theImage instanceof PlanarImageServerProxy)) {
        theImage=null;
      }
 else {
        PlanarImageServerProxy oldPISP=(PlanarImageServerProxy)theImage;
        Rectangle srcInvalidBounds=srcInvalidRegion.getBounds();
        if (srcInvalidBounds.isEmpty()) {
          int x=oldPISP.tileXToX(oldPISP.getMinTileX());
          int y=oldPISP.tileYToY(oldPISP.getMinTileY());
          int w=oldPISP.getNumXTiles() * oldPISP.getTileWidth();
          int h=oldPISP.getNumYTiles() * oldPISP.getTileHeight();
          Rectangle tileBounds=new Rectangle(x,y,w,h);
          Rectangle imageBounds=oldPISP.getBounds();
          if (!tileBounds.equals(imageBounds)) {
            Area tmpArea=new Area(tileBounds);
            tmpArea.subtract(new Area(imageBounds));
            srcInvalidRegion=tmpArea;
            srcInvalidBounds=srcInvalidRegion.getBounds();
          }
        }
        boolean saveAllTiles=false;
        ArrayList validTiles=null;
        if (srcInvalidBounds.isEmpty()) {
          invalidRegion=srcInvalidRegion;
          saveAllTiles=true;
        }
 else {
          int idx=nodeSources.indexOf(evtSrc);
          Rectangle dstRegionBounds=oldPISP.mapSourceRect(srcInvalidBounds,idx);
          if (dstRegionBounds == null) {
            dstRegionBounds=oldPISP.getBounds();
          }
          Point[] indices=getTileIndices(dstRegionBounds);
          int numIndices=indices != null ? indices.length : 0;
          GeneralPath gp=null;
          for (int i=0; i < numIndices; i++) {
            if (i % 1000 == 0 && gp != null)             gp=new GeneralPath(new Area(gp));
            Rectangle dstRect=getTileRect(indices[i].x,indices[i].y);
            Rectangle srcRect=oldPISP.mapDestRect(dstRect,idx);
            if (srcRect == null) {
              gp=null;
              break;
            }
            if (srcInvalidRegion.intersects(srcRect)) {
              if (gp == null) {
                gp=new GeneralPath(dstRect);
              }
 else {
                gp.append(dstRect,false);
              }
            }
 else {
              if (validTiles == null) {
                validTiles=new ArrayList();
              }
              validTiles.add(indices[i]);
            }
          }
          invalidRegion=(gp == null) ? null : new Area(gp);
        }
        TileCache oldCache=oldPISP.getTileCache();
        theImage=null;
        if (oldCache != null && (saveAllTiles || validTiles != null)) {
          newEventRendering(protocolName,oldPISP,(PropertyChangeEventJAI)evt);
          if (theImage instanceof PlanarImageServerProxy && ((PlanarImageServerProxy)theImage).getTileCache() != null) {
            PlanarImageServerProxy newPISP=(PlanarImageServerProxy)theImage;
            TileCache newCache=newPISP.getTileCache();
            Object tileCacheMetric=newPISP.getTileCacheMetric();
            if (saveAllTiles) {
              Raster[] tiles=oldCache.getTiles(oldPISP);
              int numTiles=tiles == null ? 0 : tiles.length;
              for (int i=0; i < numTiles; i++) {
                Raster tile=tiles[i];
                int tx=newPISP.XToTileX(tile.getMinX());
                int ty=newPISP.YToTileY(tile.getMinY());
                newCache.add(newPISP,tx,ty,tile,tileCacheMetric);
              }
            }
 else {
              int numValidTiles=validTiles.size();
              for (int i=0; i < numValidTiles; i++) {
                Point tileIndex=(Point)validTiles.get(i);
                Raster tile=oldCache.getTile(oldPISP,tileIndex.x,tileIndex.y);
                if (tile != null) {
                  newCache.add(newPISP,tileIndex.x,tileIndex.y,tile,tileCacheMetric);
                }
              }
            }
          }
        }
      }
    }
 else {
      ParameterBlock oldPB=null;
      ParameterBlock newPB=null;
      String oldServerName=serverName;
      String newServerName=serverName;
      boolean checkInvalidRegion=false;
      if (propName.equals("String_Node_Str")) {
        if (theImage instanceof PlanarImageServerProxy) {
          newEventRendering(protocolName,(PlanarImageServerProxy)theImage,(PropertyChangeEventJAI)evt);
        }
 else {
          theImage=null;
          createRendering();
        }
        shouldFireEvent=true;
      }
 else       if (propName.equals("String_Node_Str")) {
        oldPB=(ParameterBlock)evt.getOldValue();
        newPB=(ParameterBlock)evt.getNewValue();
        checkInvalidRegion=true;
      }
 else       if (propName.equals("String_Node_Str")) {
        Vector params=nodeSupport.getParameterBlock().getParameters();
        oldPB=new ParameterBlock((Vector)evt.getOldValue(),params);
        newPB=new ParameterBlock((Vector)evt.getNewValue(),params);
        checkInvalidRegion=true;
      }
 else       if (propName.equals("String_Node_Str")) {
        oldPB=new ParameterBlock(nodeSources,(Vector)evt.getOldValue());
        newPB=new ParameterBlock(nodeSources,(Vector)evt.getNewValue());
        checkInvalidRegion=true;
      }
 else       if (propName.equals("String_Node_Str")) {
        oldPB=newPB=nodeSupport.getParameterBlock();
        checkInvalidRegion=true;
      }
 else       if (propName.equals("String_Node_Str")) {
        oldPB=newPB=nodeSupport.getParameterBlock();
        oldServerName=(String)evt.getOldValue();
        newServerName=(String)evt.getNewValue();
        checkInvalidRegion=true;
      }
 else       if (evt instanceof CollectionChangeEvent) {
        int collectionIndex=nodeSources.indexOf(evtSrc);
        Vector oldSources=(Vector)nodeSources.clone();
        Vector newSources=(Vector)nodeSources.clone();
        oldSources.set(collectionIndex,evt.getOldValue());
        newSources.set(collectionIndex,evt.getNewValue());
        Vector params=nodeSupport.getParameterBlock().getParameters();
        oldPB=new ParameterBlock(oldSources,params);
        newPB=new ParameterBlock(newSources,params);
        checkInvalidRegion=true;
      }
      if (checkInvalidRegion) {
        shouldFireEvent=true;
        OperationRegistry registry=nodeSupport.getRegistry();
        RemoteDescriptor odesc=(RemoteDescriptor)registry.getDescriptor(RemoteDescriptor.class,protocolName);
        oldPB=ImageUtil.evaluateParameters(oldPB);
        newPB=ImageUtil.evaluateParameters(newPB);
        invalidRegion=(Shape)odesc.getInvalidRegion("String_Node_Str",oldServerName,oldPB,oldHints,newServerName,newPB,nodeSupport.getRenderingHints(),this);
        if (invalidRegion == null || !(theImage instanceof PlanarImageServerProxy)) {
          theImage=null;
        }
 else {
          PlanarImageServerProxy oldRendering=(PlanarImageServerProxy)theImage;
          newEventRendering(protocolName,oldRendering,(PropertyChangeEventJAI)evt);
          if (theImage instanceof PlanarImageServerProxy && oldRendering.getTileCache() != null && ((PlanarImageServerProxy)theImage).getTileCache() != null) {
            PlanarImageServerProxy newRendering=(PlanarImageServerProxy)theImage;
            TileCache oldCache=oldRendering.getTileCache();
            TileCache newCache=newRendering.getTileCache();
            Object tileCacheMetric=newRendering.getTileCacheMetric();
            if (invalidRegion.getBounds().isEmpty()) {
              int x=oldRendering.tileXToX(oldRendering.getMinTileX());
              int y=oldRendering.tileYToY(oldRendering.getMinTileY());
              int w=oldRendering.getNumXTiles() * oldRendering.getTileWidth();
              int h=oldRendering.getNumYTiles() * oldRendering.getTileHeight();
              Rectangle tileBounds=new Rectangle(x,y,w,h);
              Rectangle imageBounds=oldRendering.getBounds();
              if (!tileBounds.equals(imageBounds)) {
                Area tmpArea=new Area(tileBounds);
                tmpArea.subtract(new Area(imageBounds));
                invalidRegion=tmpArea;
              }
            }
            if (invalidRegion.getBounds().isEmpty()) {
              Raster[] tiles=oldCache.getTiles(oldRendering);
              int numTiles=tiles == null ? 0 : tiles.length;
              for (int i=0; i < numTiles; i++) {
                Raster tile=tiles[i];
                int tx=newRendering.XToTileX(tile.getMinX());
                int ty=newRendering.YToTileY(tile.getMinY());
                newCache.add(newRendering,tx,ty,tile,tileCacheMetric);
              }
            }
 else {
              Raster[] tiles=oldCache.getTiles(oldRendering);
              int numTiles=tiles == null ? 0 : tiles.length;
              for (int i=0; i < numTiles; i++) {
                Raster tile=tiles[i];
                Rectangle bounds=tile.getBounds();
                if (!invalidRegion.intersects(bounds)) {
                  newCache.add(newRendering,newRendering.XToTileX(bounds.x),newRendering.YToTileY(bounds.y),tile,tileCacheMetric);
                }
              }
            }
          }
        }
      }
    }
    if (theOldImage instanceof PlanarImageServerProxy && theImage == null) {
      newEventRendering(protocolName,(PlanarImageServerProxy)theOldImage,(PropertyChangeEventJAI)evt);
    }
 else {
      createRendering();
    }
    if (shouldFireEvent) {
      resetProperties(true);
      RenderingChangeEvent rcEvent=new RenderingChangeEvent(this,theOldImage,theImage,invalidRegion);
      eventManager.firePropertyChange(rcEvent);
      Vector sinks=getSinks();
      if (sinks != null) {
        int numSinks=sinks.size();
        for (int i=0; i < numSinks; i++) {
          Object sink=sinks.get(i);
          if (sink instanceof PropertyChangeListener) {
            ((PropertyChangeListener)sink).propertyChange(rcEvent);
          }
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Implementation of <code>PropertyChangeListener</code>. <p> When invoked with an event which is an instance of <code>RenderingChangeEvent</code> the node will respond by re-rendering itself while retaining any tiles possible.
 */
public synchronized void propertyChange(PropertyChangeEvent evt){
  Object evtSrc=evt.getSource();
  Vector nodeSources=nodeSupport.getParameterBlock().getSources();
  String propName=evt.getPropertyName().toLowerCase(Locale.ENGLISH);
  if (theImage != null && ((evt instanceof PropertyChangeEventJAI && evtSrc == this && !(evt instanceof PropertySourceChangeEvent) && nodeEventNames.contains(propName)) || ((evt instanceof RenderingChangeEvent || evt instanceof CollectionChangeEvent || (evt instanceof PropertyChangeEventJAI && evtSrc instanceof RenderedImage && propName.equals("String_Node_Str"))) && nodeSources.contains(evtSrc)))) {
    PlanarImage theOldImage=theImage;
    boolean shouldFireEvent=false;
    Shape invalidRegion=null;
    if (evtSrc == this && (propName.equals("String_Node_Str") || propName.equals("String_Node_Str") || propName.equals("String_Node_Str"))) {
      shouldFireEvent=true;
      theImage=null;
    }
 else     if (evt instanceof RenderingChangeEvent || (evtSrc instanceof RenderedImage && propName.equals("String_Node_Str"))) {
      shouldFireEvent=true;
      Shape srcInvalidRegion=null;
      if (evt instanceof RenderingChangeEvent) {
        RenderingChangeEvent rcEvent=(RenderingChangeEvent)evt;
        srcInvalidRegion=rcEvent.getInvalidRegion();
        if (srcInvalidRegion == null) {
          srcInvalidRegion=((PlanarImage)rcEvent.getOldValue()).getBounds();
        }
      }
 else {
        srcInvalidRegion=(Shape)evt.getNewValue();
        if (srcInvalidRegion == null) {
          RenderedImage rSrc=(RenderedImage)evtSrc;
          srcInvalidRegion=new Rectangle(rSrc.getMinX(),rSrc.getMinY(),rSrc.getWidth(),rSrc.getHeight());
        }
      }
      if (!(theImage instanceof PlanarImageServerProxy)) {
        theImage=null;
      }
 else {
        PlanarImageServerProxy oldPISP=(PlanarImageServerProxy)theImage;
        Rectangle srcInvalidBounds=srcInvalidRegion.getBounds();
        if (srcInvalidBounds.isEmpty()) {
          int x=oldPISP.tileXToX(oldPISP.getMinTileX());
          int y=oldPISP.tileYToY(oldPISP.getMinTileY());
          int w=oldPISP.getNumXTiles() * oldPISP.getTileWidth();
          int h=oldPISP.getNumYTiles() * oldPISP.getTileHeight();
          Rectangle tileBounds=new Rectangle(x,y,w,h);
          Rectangle imageBounds=oldPISP.getBounds();
          if (!tileBounds.equals(imageBounds)) {
            Area tmpArea=new Area(tileBounds);
            tmpArea.subtract(new Area(imageBounds));
            srcInvalidRegion=tmpArea;
            srcInvalidBounds=srcInvalidRegion.getBounds();
          }
        }
        boolean saveAllTiles=false;
        ArrayList validTiles=null;
        if (srcInvalidBounds.isEmpty()) {
          invalidRegion=srcInvalidRegion;
          saveAllTiles=true;
        }
 else {
          int idx=nodeSources.indexOf(evtSrc);
          Rectangle dstRegionBounds=oldPISP.mapSourceRect(srcInvalidBounds,idx);
          if (dstRegionBounds == null) {
            dstRegionBounds=oldPISP.getBounds();
          }
          Point[] indices=getTileIndices(dstRegionBounds);
          int numIndices=indices != null ? indices.length : 0;
          GeneralPath gp=null;
          for (int i=0; i < numIndices; i++) {
            if (i % 1000 == 0 && gp != null)             gp=new GeneralPath(new Area(gp));
            Rectangle dstRect=getTileRect(indices[i].x,indices[i].y);
            Rectangle srcRect=oldPISP.mapDestRect(dstRect,idx);
            if (srcRect == null) {
              gp=null;
              break;
            }
            if (srcInvalidRegion.intersects(srcRect)) {
              if (gp == null) {
                gp=new GeneralPath(dstRect);
              }
 else {
                gp.append(dstRect,false);
              }
            }
 else {
              if (validTiles == null) {
                validTiles=new ArrayList();
              }
              validTiles.add(indices[i]);
            }
          }
          invalidRegion=(gp == null) ? null : new Area(gp);
        }
        TileCache oldCache=oldPISP.getTileCache();
        theImage=null;
        if (oldCache != null && (saveAllTiles || validTiles != null)) {
          newEventRendering(protocolName,oldPISP,(PropertyChangeEventJAI)evt);
          if (theImage instanceof PlanarImageServerProxy && ((PlanarImageServerProxy)theImage).getTileCache() != null) {
            PlanarImageServerProxy newPISP=(PlanarImageServerProxy)theImage;
            TileCache newCache=newPISP.getTileCache();
            Object tileCacheMetric=newPISP.getTileCacheMetric();
            if (saveAllTiles) {
              Raster[] tiles=oldCache.getTiles(oldPISP);
              int numTiles=tiles == null ? 0 : tiles.length;
              for (int i=0; i < numTiles; i++) {
                Raster tile=tiles[i];
                int tx=newPISP.XToTileX(tile.getMinX());
                int ty=newPISP.YToTileY(tile.getMinY());
                newCache.add(newPISP,tx,ty,tile,tileCacheMetric);
              }
            }
 else {
              int numValidTiles=validTiles.size();
              for (int i=0; i < numValidTiles; i++) {
                Point tileIndex=(Point)validTiles.get(i);
                Raster tile=oldCache.getTile(oldPISP,tileIndex.x,tileIndex.y);
                if (tile != null) {
                  newCache.add(newPISP,tileIndex.x,tileIndex.y,tile,tileCacheMetric);
                }
              }
            }
          }
        }
      }
    }
 else {
      ParameterBlock oldPB=null;
      ParameterBlock newPB=null;
      String oldServerName=serverName;
      String newServerName=serverName;
      boolean checkInvalidRegion=false;
      if (propName.equals("String_Node_Str")) {
        if (theImage instanceof PlanarImageServerProxy) {
          newEventRendering(protocolName,(PlanarImageServerProxy)theImage,(PropertyChangeEventJAI)evt);
        }
 else {
          theImage=null;
          createRendering();
        }
        shouldFireEvent=true;
      }
 else       if (propName.equals("String_Node_Str")) {
        oldPB=(ParameterBlock)evt.getOldValue();
        newPB=(ParameterBlock)evt.getNewValue();
        checkInvalidRegion=true;
      }
 else       if (propName.equals("String_Node_Str")) {
        Vector params=nodeSupport.getParameterBlock().getParameters();
        oldPB=new ParameterBlock((Vector)evt.getOldValue(),params);
        newPB=new ParameterBlock((Vector)evt.getNewValue(),params);
        checkInvalidRegion=true;
      }
 else       if (propName.equals("String_Node_Str")) {
        oldPB=new ParameterBlock(nodeSources,(Vector)evt.getOldValue());
        newPB=new ParameterBlock(nodeSources,(Vector)evt.getNewValue());
        checkInvalidRegion=true;
      }
 else       if (propName.equals("String_Node_Str")) {
        oldPB=newPB=nodeSupport.getParameterBlock();
        checkInvalidRegion=true;
      }
 else       if (propName.equals("String_Node_Str")) {
        oldPB=newPB=nodeSupport.getParameterBlock();
        oldServerName=(String)evt.getOldValue();
        newServerName=(String)evt.getNewValue();
        checkInvalidRegion=true;
      }
 else       if (evt instanceof CollectionChangeEvent) {
        int collectionIndex=nodeSources.indexOf(evtSrc);
        Vector oldSources=(Vector)nodeSources.clone();
        Vector newSources=(Vector)nodeSources.clone();
        oldSources.set(collectionIndex,evt.getOldValue());
        newSources.set(collectionIndex,evt.getNewValue());
        Vector params=nodeSupport.getParameterBlock().getParameters();
        oldPB=new ParameterBlock(oldSources,params);
        newPB=new ParameterBlock(newSources,params);
        checkInvalidRegion=true;
      }
      if (checkInvalidRegion) {
        shouldFireEvent=true;
        OperationRegistry registry=nodeSupport.getRegistry();
        RemoteDescriptor odesc=(RemoteDescriptor)registry.getDescriptor(RemoteDescriptor.class,protocolName);
        oldPB=ImageUtil.evaluateParameters(oldPB);
        newPB=ImageUtil.evaluateParameters(newPB);
        invalidRegion=(Shape)odesc.getInvalidRegion("String_Node_Str",oldServerName,oldPB,oldHints,newServerName,newPB,nodeSupport.getRenderingHints(),this);
        if (invalidRegion == null || !(theImage instanceof PlanarImageServerProxy)) {
          theImage=null;
        }
 else {
          PlanarImageServerProxy oldRendering=(PlanarImageServerProxy)theImage;
          newEventRendering(protocolName,oldRendering,(PropertyChangeEventJAI)evt);
          if (theImage instanceof PlanarImageServerProxy && oldRendering.getTileCache() != null && ((PlanarImageServerProxy)theImage).getTileCache() != null) {
            PlanarImageServerProxy newRendering=(PlanarImageServerProxy)theImage;
            TileCache oldCache=oldRendering.getTileCache();
            TileCache newCache=newRendering.getTileCache();
            Object tileCacheMetric=newRendering.getTileCacheMetric();
            if (invalidRegion.getBounds().isEmpty()) {
              int x=oldRendering.tileXToX(oldRendering.getMinTileX());
              int y=oldRendering.tileYToY(oldRendering.getMinTileY());
              int w=oldRendering.getNumXTiles() * oldRendering.getTileWidth();
              int h=oldRendering.getNumYTiles() * oldRendering.getTileHeight();
              Rectangle tileBounds=new Rectangle(x,y,w,h);
              Rectangle imageBounds=oldRendering.getBounds();
              if (!tileBounds.equals(imageBounds)) {
                Area tmpArea=new Area(tileBounds);
                tmpArea.subtract(new Area(imageBounds));
                invalidRegion=tmpArea;
              }
            }
            if (invalidRegion.getBounds().isEmpty()) {
              Raster[] tiles=oldCache.getTiles(oldRendering);
              int numTiles=tiles == null ? 0 : tiles.length;
              for (int i=0; i < numTiles; i++) {
                Raster tile=tiles[i];
                int tx=newRendering.XToTileX(tile.getMinX());
                int ty=newRendering.YToTileY(tile.getMinY());
                newCache.add(newRendering,tx,ty,tile,tileCacheMetric);
              }
            }
 else {
              Raster[] tiles=oldCache.getTiles(oldRendering);
              int numTiles=tiles == null ? 0 : tiles.length;
              for (int i=0; i < numTiles; i++) {
                Raster tile=tiles[i];
                Rectangle bounds=tile.getBounds();
                if (!invalidRegion.intersects(bounds)) {
                  newCache.add(newRendering,newRendering.XToTileX(bounds.x),newRendering.YToTileY(bounds.y),tile,tileCacheMetric);
                }
              }
            }
          }
        }
      }
    }
    if (theOldImage instanceof PlanarImageServerProxy && theImage == null) {
      newEventRendering(protocolName,(PlanarImageServerProxy)theOldImage,(PropertyChangeEventJAI)evt);
    }
 else {
      createRendering();
    }
    if (shouldFireEvent) {
      resetProperties(true);
      RenderingChangeEvent rcEvent=new RenderingChangeEvent(this,theOldImage,theImage,invalidRegion);
      eventManager.firePropertyChange(rcEvent);
      Vector sinks=getSinks();
      if (sinks != null) {
        int numSinks=sinks.size();
        for (int i=0; i < numSinks; i++) {
          Object sink=sinks.get(i);
          if (sink instanceof PropertyChangeListener) {
            ((PropertyChangeListener)sink).propertyChange(rcEvent);
          }
        }
      }
    }
  }
}