From a6e0e85170f5325d6733a740f4352e5fcc1de0d9 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Fri, 8 Nov 2002 10:11:06 +0000 Subject: [PATCH] Fixed multi-threading bugs (NPEs) Submitted by: Joachim Unger line ending correction ArrayList --> List, HashMap --> Map git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/fop-0_20_2-maintain@195451 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/fop/image/AbstractFopImage.java | 64 ++++++++++++------- src/org/apache/fop/image/FopImageFactory.java | 16 ++--- src/org/apache/fop/image/GifImage.java | 1 + 3 files changed, 49 insertions(+), 32 deletions(-) diff --git a/src/org/apache/fop/image/AbstractFopImage.java b/src/org/apache/fop/image/AbstractFopImage.java index 775df34fc..150f49cfc 100644 --- a/src/org/apache/fop/image/AbstractFopImage.java +++ b/src/org/apache/fop/image/AbstractFopImage.java @@ -137,6 +137,7 @@ public abstract class AbstractFopImage implements FopImage { */ abstract protected void loadImage() throws FopImageException; + /** * If true, image data are inverted */ @@ -158,8 +159,10 @@ public abstract class AbstractFopImage implements FopImage { * @exception FopImageException an error occured during property retriaval */ public int getWidth() throws FopImageException { - if (this.m_width == 0) - this.loadImage(); + synchronized(this) { + if (this.m_width == 0) + this.loadImage(); + } return this.m_width; } @@ -170,8 +173,10 @@ public abstract class AbstractFopImage implements FopImage { * @exception FopImageException an error occured during property retriaval */ public int getHeight() throws FopImageException { - if (this.m_height == 0) - this.loadImage(); + synchronized(this) { + if (this.m_height == 0) + this.loadImage(); + } return this.m_height; } @@ -182,8 +187,10 @@ public abstract class AbstractFopImage implements FopImage { * @exception FopImageException an error occured during property retriaval */ public ColorSpace getColorSpace() throws FopImageException { - if (this.m_colorSpace == null) - this.loadImage(); + synchronized(this) { + if (this.m_colorSpace == null) + this.loadImage(); + } return this.m_colorSpace; } @@ -194,8 +201,10 @@ public abstract class AbstractFopImage implements FopImage { * @exception FopImageException an error occured during property retriaval */ public int getBitsPerPixel() throws FopImageException { - if (this.m_bitsPerPixel == 0) - this.loadImage(); + synchronized(this) { + if (this.m_bitsPerPixel == 0) + this.loadImage(); + } return this.m_bitsPerPixel; } @@ -224,8 +233,10 @@ public abstract class AbstractFopImage implements FopImage { * @exception FopImageException an error occured during loading */ public byte[] getBitmaps() throws FopImageException { - if (this.m_bitmaps == null) - this.loadImage(); + synchronized(this) { + if (this.m_bitmaps == null) + this.loadImage(); + } return this.m_bitmaps; } @@ -236,8 +247,10 @@ public abstract class AbstractFopImage implements FopImage { * @exception FopImageException an error occured during loading */ public int getBitmapsSize() throws FopImageException { - if (this.m_bitmapsSize == 0) - this.loadImage(); + synchronized(this) { + if (this.m_bitmapsSize == 0) + this.loadImage(); + } return this.m_bitmapsSize; } @@ -272,8 +285,10 @@ public abstract class AbstractFopImage implements FopImage { * Using the bitsPerPixel var as our flag since many imges will * have a null m_compressionType even after being loaded */ - if (this.m_bitsPerPixel == 0) - this.loadImage(); + synchronized(this) { + if (this.m_bitsPerPixel == 0) + this.loadImage(); + } return m_compressionType; } @@ -282,21 +297,24 @@ public abstract class AbstractFopImage implements FopImage { * Free all ressource. */ public void close() { + //org.apache.fop.messaging.MessageHandler.debug(getClass().getName()+".close(): "+this.m_href); /* * For the moment, only release the bitmaps (image areas * can share the same FopImage object) * Thus, even if it had been called, other properties * are still available. */ - // this.m_width = 0; - // this.m_height = 0; - // this.m_href = null; - // this.m_colorSpace = null; - // this.m_bitsPerPixel = 0; - this.m_bitmaps = null; - this.m_bitmapsSize = 0; - // this.m_isTransparent = false; - // this.m_transparentColor = null; + synchronized(this) { + // this.m_width = 0; + // this.m_height = 0; + // this.m_href = null; + // this.m_colorSpace = null; + // this.m_bitsPerPixel = 0; + this.m_bitmaps = null; + this.m_bitmapsSize = 0; + // this.m_isTransparent = false; + // this.m_transparentColor = null; + } } } diff --git a/src/org/apache/fop/image/FopImageFactory.java b/src/org/apache/fop/image/FopImageFactory.java index 00eaa943e..b672446ce 100644 --- a/src/org/apache/fop/image/FopImageFactory.java +++ b/src/org/apache/fop/image/FopImageFactory.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -19,7 +19,7 @@ import java.io.File; import java.net.URL; import java.net.MalformedURLException; import java.lang.reflect.Constructor; -import java.util.HashMap; +import java.util.Map; /** * create FopImage objects (with a configuration file - not yet implemented). @@ -27,7 +27,7 @@ import java.util.HashMap; */ public class FopImageFactory { - private static HashMap m_urlMap = new HashMap(); + private static Map m_urlMap = new java.util.HashMap(); /** * create an FopImage objects. @@ -81,18 +81,16 @@ public class FopImageFactory { + e_context.getMessage()); } catch (Exception e) { // maybe relative - URL context_url = null; - String base = Configuration.getStringValue("baseDir"); + URL baseURL = Configuration.getBaseURL(); - if (base == null) { + if (baseURL == null) { throw new FopImageException("Error with image URL: " + e.getMessage() - + " and no base directory is specified"); + + " and no base URL is specified"); } try { - absoluteURL = new URL(Configuration.getStringValue("baseDir") - + absoluteURL.getFile()); + absoluteURL = new URL(baseURL, absoluteURL.getFile()); } catch (MalformedURLException e_context) { // pb context url throw new FopImageException("Invalid Image URL - error on relative URL : " diff --git a/src/org/apache/fop/image/GifImage.java b/src/org/apache/fop/image/GifImage.java index 5c64b0bfb..7bef85ab6 100644 --- a/src/org/apache/fop/image/GifImage.java +++ b/src/org/apache/fop/image/GifImage.java @@ -36,6 +36,7 @@ public class GifImage extends AbstractFopImage { } protected void loadImage() throws FopImageException { + //org.apache.fop.messaging.MessageHandler.debug(getClass().getName()+".loadImage(): "+this.m_href); int[] tmpMap = null; try { ImageProducer ip = (ImageProducer)this.m_href.getContent(); -- 2.39.5