]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Fix 4-instance findbug warnings.
authorGlenn Adams <gadams@apache.org>
Fri, 8 Aug 2014 03:48:54 +0000 (03:48 +0000)
committerGlenn Adams <gadams@apache.org>
Fri, 8 Aug 2014 03:48:54 +0000 (03:48 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1616668 13f79535-47bb-0310-9956-ffa450edef68

14 files changed:
findbugs-exclude.xml
src/java/org/apache/fop/afp/util/StringUtils.java
src/java/org/apache/fop/fonts/autodetect/WindowsFontDirFinder.java
src/java/org/apache/fop/fonts/substitute/FontQualifier.java
src/java/org/apache/fop/render/bitmap/PNGRenderer.java
src/java/org/apache/fop/render/bitmap/TIFFRenderer.java
src/java/org/apache/fop/render/pdf/ImageRawPNGAdapter.java
src/java/org/apache/fop/render/ps/ImageEncoderPNG.java
src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java
src/java/org/apache/fop/render/rtf/rtflib/tools/ImageUtil.java
src/java/org/apache/fop/render/rtf/rtflib/tools/TableContext.java
src/java/org/apache/fop/svg/PDFDocumentGraphics2DConfigurator.java
src/java/org/apache/fop/tools/TestConverter.java
src/java/org/apache/fop/tools/anttasks/Fop.java

index c11fdc732db020445b5a32f64c7d136977a1c3cb..2deaa263f9ff020a5ede17ac24360d20627f3c61 100644 (file)
     <!-- 27 warnings -->
     <Bug pattern="DLS_DEAD_LOCAL_STORE"/>
   </Match>
-  <Match>
-    <!-- 4 warnings -->
-    <Bug pattern="DM_BOOLEAN_CTOR"/>
-  </Match>
   <Match>
     <!-- 29 warnings -->
     <Bug pattern="DM_CONVERT_CASE"/>
     <!-- 88 warnings -->
     <Bug pattern="DM_NUMBER_CTOR"/>
   </Match>
-  <Match>
-    <!-- 4 warnings -->
-    <Bug pattern="DM_STRING_VOID_CTOR"/>
-  </Match>
   <Match>
     <!-- 84 warnings -->
     <Bug pattern="EI_EXPOSE_REP"/>
     <!-- 5 warnings -->
     <Bug pattern="NM_SAME_SIMPLE_NAME_AS_SUPERCLASS"/>
   </Match>
-  <Match>
-    <!-- 4 warnings -->
-    <Bug pattern="NP_LOAD_OF_KNOWN_NULL_VALUE"/>
-  </Match>
-  <Match>
-    <!-- 4 warnings -->
-    <Bug pattern="NP_NULL_ON_SOME_PATH"/>
-  </Match>
-  <Match>
-    <!-- 4 warnings -->
-    <Bug pattern="OS_OPEN_STREAM"/>
-  </Match>
   <Match>
     <!-- 46 warnings -->
     <Bug pattern="PZLA_PREFER_ZERO_LENGTH_ARRAYS"/>
index ab5d6013b9fff529b468a29b69dce061c49b0e68..26dfc5c1a14145c32e5c3bae6f9be1c03e8c9b62 100644 (file)
@@ -39,7 +39,7 @@ public final class StringUtils {
     public static String lpad(String input, char padding, int length) {
 
         if (input == null) {
-            input = new String();
+            input = "";
         }
 
         if (input.length() >= length) {
@@ -66,7 +66,7 @@ public final class StringUtils {
     public static String rpad(String input, char padding, int length) {
 
         if (input == null) {
-            input = new String();
+            input = "";
         }
 
         if (input.length() >= length) {
index 53b076073b6e44630e96885c80e5d654c5842f37..bd506d9ed85681fc38d4da1e922cf8e3a57fe15e 100644 (file)
@@ -25,6 +25,8 @@ import java.io.IOException;
 import java.io.InputStreamReader;
 import java.util.List;
 
+import org.apache.commons.io.IOUtils;
+
 /**
  * FontFinder for native Windows platforms
  */
@@ -42,9 +44,18 @@ public class WindowsFontDirFinder implements FontDirFinder {
         } else {
             process = runtime.exec("cmd.exe /c echo %windir%");
         }
-        BufferedReader bufferedReader = new BufferedReader(
-                new InputStreamReader(process.getInputStream()));
-        return bufferedReader.readLine();
+        InputStreamReader isr = null;
+        BufferedReader bufferedReader = null;
+        String dir = "";
+        try {
+            isr = new InputStreamReader(process.getInputStream());
+            bufferedReader = new BufferedReader(isr);
+            dir = bufferedReader.readLine();
+        } finally {
+            IOUtils.closeQuietly(bufferedReader);
+            IOUtils.closeQuietly(isr);
+        }
+        return dir;
     }
 
     /**
index b7473d72f46c39fb9dd1171020143226c1ca69be..8e9213e9db766285fee6a1fde5d8d0682de1b384 100644 (file)
@@ -285,7 +285,7 @@ public class FontQualifier {
      * {@inheritDoc}
      */
     public String toString() {
-        String str = new String();
+        String str = "";
         if (fontFamilyAttributeValue != null) {
             str += "font-family=" + fontFamilyAttributeValue;
         }
index 6f45d18ca721dbc8af86fa8f1b963fccbea64fea..623b286182a05415d9a00f4e8205cd5de8aa92e3 100644 (file)
@@ -118,11 +118,12 @@ public class PNGRenderer extends Java2DRenderer {
                 = BitmapRendererEventProducer.Provider.get(
                         getUserAgent().getEventBroadcaster());
             eventProducer.noImageWriterFound(this, getMimeType());
+        } else {
+            if (log.isDebugEnabled()) {
+                log.debug("Writing image using " + writer.getClass().getName());
+            }
+            writer.writeImage(image, os, params);
         }
-        if (log.isDebugEnabled()) {
-            log.debug("Writing image using " + writer.getClass().getName());
-        }
-        writer.writeImage(image, os, params);
     }
 
     /**
index 619d0625e4165c859c368ef30466dd8b5ffcf114..442660c3b93dca1849f12c55593272d12f8497a7 100644 (file)
@@ -117,35 +117,35 @@ public class TIFFRenderer extends Java2DRenderer {
                 = BitmapRendererEventProducer.Provider.get(
                         getUserAgent().getEventBroadcaster());
             eventProducer.noImageWriterFound(this, getMimeType());
-        }
-        if (writer.supportsMultiImageWriter()) {
-            MultiImageWriter multiWriter = writer.createMultiImageWriter(outputStream);
-            try {
-                // Write all pages/images
-                while (pageImagesItr.hasNext()) {
-                    RenderedImage img = (RenderedImage) pageImagesItr.next();
-                    multiWriter.writeImage(img, imageSettings.getWriterParams());
-                }
-            } finally {
-                multiWriter.close();
-            }
         } else {
-            RenderedImage renderedImage = null;
-            if (pageImagesItr.hasNext()) {
-                renderedImage = (RenderedImage) pageImagesItr.next();
-            }
-            writer.writeImage(renderedImage, outputStream, imageSettings.getWriterParams());
-            if (pageImagesItr.hasNext()) {
-                BitmapRendererEventProducer eventProducer
-                    = BitmapRendererEventProducer.Provider.get(
-                            getUserAgent().getEventBroadcaster());
-                eventProducer.stoppingAfterFirstPageNoFilename(this);
+            if (writer.supportsMultiImageWriter()) {
+                MultiImageWriter multiWriter = writer.createMultiImageWriter(outputStream);
+                try {
+                    // Write all pages/images
+                    while (pageImagesItr.hasNext()) {
+                        RenderedImage img = (RenderedImage) pageImagesItr.next();
+                        multiWriter.writeImage(img, imageSettings.getWriterParams());
+                    }
+                } finally {
+                    multiWriter.close();
+                }
+            } else {
+                RenderedImage renderedImage = null;
+                if (pageImagesItr.hasNext()) {
+                    renderedImage = (RenderedImage) pageImagesItr.next();
+                }
+                writer.writeImage(renderedImage, outputStream, imageSettings.getWriterParams());
+                if (pageImagesItr.hasNext()) {
+                    BitmapRendererEventProducer eventProducer
+                        = BitmapRendererEventProducer.Provider.get(
+                                getUserAgent().getEventBroadcaster());
+                    eventProducer.stoppingAfterFirstPageNoFilename(this);
+                }
             }
+            // Cleaning
+            outputStream.flush();
+            clearViewportList();
         }
-
-        // Cleaning
-        outputStream.flush();
-        clearViewportList();
         log.debug("TIFF encoding done.");
     }
 
index 5f69fbadbb4656ba0ca9358d83370ba51f91380e..f40ca6d943b868522e368dca1a4fda997453abd0 100644 (file)
@@ -119,13 +119,15 @@ public class ImageRawPNGAdapter extends AbstractImageAdapter {
             ByteArrayOutputStream baos = null;\r
             DeflaterOutputStream dos = null;\r
             InputStream in = null;\r
+            InflaterInputStream infStream = null;\r
+            DataInputStream dataStream = null;\r
             try {\r
                 baos = new ByteArrayOutputStream();\r
                 dos = new DeflaterOutputStream(baos, new Deflater());\r
                 in = ((ImageRawStream) image).createInputStream();\r
                 try {\r
-                    InflaterInputStream infStream = new InflaterInputStream(in, new Inflater());\r
-                    DataInputStream dataStream = new DataInputStream(infStream);\r
+                    infStream = new InflaterInputStream(in, new Inflater());\r
+                    dataStream = new DataInputStream(infStream);\r
                     // offset is the byte offset of the alpha component\r
                     int offset = numberOfInterleavedComponents - 1; // 1 for GA, 3 for RGBA\r
                     int numColumns = image.getSize().getWidthPx();\r
@@ -159,12 +161,13 @@ public class ImageRawPNGAdapter extends AbstractImageAdapter {
                 }\r
                 BitmapImage alphaMask = new BitmapImage("Mask:" + this.getKey(), image.getSize().getWidthPx(),\r
                         image.getSize().getHeightPx(), baos.toByteArray(), null);\r
-                IOUtils.closeQuietly(baos);\r
                 alphaMask.setPDFFilter(transFlate);\r
                 alphaMask.disallowMultipleFilters();\r
                 alphaMask.setColorSpace(new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_GRAY));\r
                 softMask = doc.addImage(null, alphaMask).makeReference();\r
             } finally {\r
+                IOUtils.closeQuietly(infStream);\r
+                IOUtils.closeQuietly(dataStream);\r
                 IOUtils.closeQuietly(in);\r
                 IOUtils.closeQuietly(dos);\r
                 IOUtils.closeQuietly(baos);\r
@@ -216,7 +219,9 @@ public class ImageRawPNGAdapter extends AbstractImageAdapter {
     /** {@inheritDoc} */\r
     public void outputContents(OutputStream out) throws IOException {\r
         InputStream in = ((ImageRawStream) image).createInputStream();\r
-\r
+        InflaterInputStream infStream = null;\r
+        DataInputStream dataStream = null;\r
+        DeflaterOutputStream dos = null;\r
         try {\r
             if (numberOfInterleavedComponents == 1 || numberOfInterleavedComponents == 3) {\r
                 // means we have Gray, RGB, or Palette\r
@@ -226,14 +231,14 @@ public class ImageRawPNGAdapter extends AbstractImageAdapter {
                 // TODO: since we have alpha here do this when the alpha channel is extracted\r
                 int numBytes = numberOfInterleavedComponents - 1; // 1 for Gray, 3 for RGB\r
                 int numColumns = image.getSize().getWidthPx();\r
-                InflaterInputStream infStream = new InflaterInputStream(in, new Inflater());\r
-                DataInputStream dataStream = new DataInputStream(infStream);\r
+                infStream = new InflaterInputStream(in, new Inflater());\r
+                dataStream = new DataInputStream(infStream);\r
                 int offset = 0;\r
                 int bytesPerRow = numberOfInterleavedComponents * numColumns;\r
                 int filter;\r
                 // here we need to inflate the PNG pixel data, which includes alpha, separate the alpha\r
                 // channel and then deflate the RGB channels back again\r
-                DeflaterOutputStream dos = new DeflaterOutputStream(out, new Deflater());\r
+                dos = new DeflaterOutputStream(out, new Deflater());\r
                 while ((filter = dataStream.read()) != -1) {\r
                     byte[] bytes = new byte[bytesPerRow];\r
                     dataStream.readFully(bytes, 0, bytesPerRow);\r
@@ -244,9 +249,11 @@ public class ImageRawPNGAdapter extends AbstractImageAdapter {
                     }\r
                     offset = 0;\r
                 }\r
-                dos.close();\r
             }\r
         } finally {\r
+            IOUtils.closeQuietly(dos);\r
+            IOUtils.closeQuietly(dataStream);\r
+            IOUtils.closeQuietly(infStream);\r
             IOUtils.closeQuietly(in);\r
         }\r
     }\r
index 5746a3fbe0c27f11ea4b8332750e6875fa94f79c..8ab91cb0a30a6b40c0f383d7cf1ce058c93d7509 100644 (file)
@@ -65,6 +65,10 @@ public class ImageEncoderPNG implements ImageEncoder {
     public void writeTo(OutputStream out) throws IOException {
         // TODO: refactor this code with equivalent PDF code
         InputStream in = ((ImageRawStream) image).createInputStream();
+        InflaterInputStream infStream = null;
+        DataInputStream dataStream = null;
+        ByteArrayOutputStream baos = null;
+        DeflaterOutputStream dos = null;
         try {
             if (numberOfInterleavedComponents == 1 || numberOfInterleavedComponents == 3) {
                 // means we have Gray, RGB, or Palette
@@ -73,8 +77,8 @@ public class ImageEncoderPNG implements ImageEncoder {
                 // means we have Gray + alpha or RGB + alpha
                 int numBytes = numberOfInterleavedComponents - 1; // 1 for Gray, 3 for RGB
                 int numColumns = image.getSize().getWidthPx();
-                InflaterInputStream infStream = new InflaterInputStream(in, new Inflater());
-                DataInputStream dataStream = new DataInputStream(infStream);
+                infStream = new InflaterInputStream(in, new Inflater());
+                dataStream = new DataInputStream(infStream);
                 int offset = 0;
                 int bytesPerRow = numberOfInterleavedComponents * numColumns;
                 int filter;
@@ -83,8 +87,8 @@ public class ImageEncoderPNG implements ImageEncoder {
                 // TODO: not using the baos below and using the original out instead (as happens in PDF)
                 // would be preferable but that does not work with the rest of the postscript code; this
                 // needs to be revisited
-                ByteArrayOutputStream baos = new ByteArrayOutputStream();
-                DeflaterOutputStream dos = new DeflaterOutputStream(/* out */baos, new Deflater());
+                baos = new ByteArrayOutputStream();
+                dos = new DeflaterOutputStream(/* out */baos, new Deflater());
                 while ((filter = dataStream.read()) != -1) {
                     byte[] bytes = new byte[bytesPerRow];
                     dataStream.readFully(bytes, 0, bytesPerRow);
@@ -99,6 +103,10 @@ public class ImageEncoderPNG implements ImageEncoder {
                 IOUtils.copy(new ByteArrayInputStream(baos.toByteArray()), out);
             }
         } finally {
+            IOUtils.closeQuietly(dos);
+            IOUtils.closeQuietly(baos);
+            IOUtils.closeQuietly(dataStream);
+            IOUtils.closeQuietly(infStream);
             IOUtils.closeQuietly(in);
         }
     }
index 5013e095837466c5e2bd93a38e8754c6ca1b75a2..8dd58739cd026881463c927c981beb6f70c50107 100644 (file)
@@ -168,7 +168,7 @@ public class RtfTableRow extends RtfContainer implements ITableAttributes {
         }
 
         //check for keep-together
-        if (attrib != null && attrib.isSet(ITableAttributes.ROW_KEEP_TOGETHER)) {
+        if (attrib.isSet(ITableAttributes.ROW_KEEP_TOGETHER)) {
             writeControlWord(ROW_KEEP_TOGETHER);
         }
 
index 0ee70bf3118c45356be7bd61af8a83a781d0523b..fb590ab6355f079eb2dd78ff51a4fa2e5896bfff 100644 (file)
@@ -58,7 +58,7 @@ public final class ImageUtil {
      *         number  The digits as integer
      */
     public static int getInt(String value) {
-        String retString = new String();
+        String retString = "";
         StringBuffer s = new StringBuffer(value);
         int len = s.length();
 
index 85f1261f705d19fe907ac4ba01579dd3090f678c..3e1aca1c1ffb26eb584f8e56a02decbaa00f751a 100644 (file)
@@ -168,9 +168,9 @@ public class TableContext implements ITableColumnsInfo {
             while (colIndex >= colFirstSpanningCol.size()) {
                 setNextFirstSpanningCol(false);
             }
-            colFirstSpanningCol.set(colIndex, new Boolean(bFirstSpanningCol));
+            colFirstSpanningCol.set(colIndex, Boolean.valueOf(bFirstSpanningCol));
         } else {
-            colFirstSpanningCol.add(new Boolean(bFirstSpanningCol));
+            colFirstSpanningCol.add(Boolean.valueOf(bFirstSpanningCol));
         }
     }
 
@@ -181,7 +181,7 @@ public class TableContext implements ITableColumnsInfo {
      */
     public void setNextFirstSpanningCol(
             boolean bFirstSpanningCol) {
-        colFirstSpanningCol.add(new Boolean(bFirstSpanningCol));
+        colFirstSpanningCol.add(Boolean.valueOf(bFirstSpanningCol));
     }
 
     /**
@@ -202,7 +202,7 @@ public class TableContext implements ITableColumnsInfo {
 
             if (i.intValue() == 0) {
                 colRowSpanningAttrs.set(z, null);
-                colFirstSpanningCol.set(z, new Boolean(false));
+                colFirstSpanningCol.set(z, Boolean.valueOf(false));
             }
         }
     }
index 6f2d4429da26fdd1287b51fe413bf1a1b5a2dcfe..a8e9307a7b70292e56fd66c3847b347be9f65a75 100644 (file)
@@ -34,7 +34,6 @@ import org.apache.fop.fonts.DefaultFontConfigurator;
 import org.apache.fop.fonts.EmbedFontInfo;
 import org.apache.fop.fonts.FontCacheManagerFactory;
 import org.apache.fop.fonts.FontDetectorFactory;
-import org.apache.fop.fonts.FontEventListener;
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.fonts.FontManager;
 import org.apache.fop.fonts.FontSetup;
@@ -97,12 +96,11 @@ public class PDFDocumentGraphics2DConfigurator {
             //TODO Make use of fontBaseURL, font substitution and referencing configuration
             //Requires a change to the expected configuration layout
 
-            final FontEventListener listener = null;
             DefaultFontConfig.DefaultFontConfigParser parser
                     = new DefaultFontConfig.DefaultFontConfigParser();
             DefaultFontConfig fontInfoConfig = parser.parse(cfg, strict);
             DefaultFontConfigurator fontInfoConfigurator
-                    = new DefaultFontConfigurator(fontManager, listener, strict);
+                    = new DefaultFontConfigurator(fontManager, null, strict);
             List<EmbedFontInfo> fontInfoList = fontInfoConfigurator.configure(fontInfoConfig);
             fontManager.saveCache();
             FontSetup.setup(fontInfo, fontInfoList, resourceResolver, useComplexScriptFeatures);
index 027c3503755b4bb6eb9d9e48641ba4f3dadef2d8..8e0d0bca98c7de653d772d3ad2bdfd98b4520193 100644 (file)
@@ -78,6 +78,7 @@ public class TestConverter {
     public static void main(String[] args) {
         if (args == null || args.length == 0) {
             System.out.println("test suite file name required");
+            return;
         }
         TestConverter tc = new TestConverter();
 
@@ -284,8 +285,8 @@ public class TestConverter {
             FopFactory fopFactory = FopFactory.newInstance(baseUri);
             FOUserAgent userAgent = fopFactory.newFOUserAgent();
 
-            userAgent.getRendererOptions().put("fineDetail", new Boolean(false));
-            userAgent.getRendererOptions().put("consistentOutput", new Boolean(true));
+            userAgent.getRendererOptions().put("fineDetail", Boolean.valueOf(false));
+            userAgent.getRendererOptions().put("consistentOutput", Boolean.valueOf(true));
             userAgent.setProducer("Testsuite Converter");
 
             String outname = res;
@@ -311,7 +312,7 @@ public class TestConverter {
                 File f1 = new File(destdir, outname + ".at.xml");
                 File f2 = new File(compare, outname + ".at.xml");
                 if (!compareFiles(f1, f2)) {
-                    differ.put(outname + ".at.xml", new Boolean(pass));
+                    differ.put(outname + ".at.xml", Boolean.valueOf(pass));
                 }
             }
         } catch (Exception e) {
index 8ca048da3c4a4083ef52f5a04f649ccc9a80950a..8460e5964c6296a46570ed94694bdaa6fd1db1cb 100644 (file)
@@ -26,7 +26,6 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.net.URI;
 import java.util.List;
-import java.util.Vector;
 
 import org.xml.sax.SAXException;
 
@@ -678,8 +677,7 @@ class FOPTaskStarter {
 
     private void render(File xmlFile, File xsltFile, File outFile, String outputFormat) {
         //TODO: implement support for XSLT params
-        final Vector xsltParams = null;
-        InputHandler inputHandler = new InputHandler(xmlFile, xsltFile, xsltParams);
+        InputHandler inputHandler = new InputHandler(xmlFile, xsltFile, null);
         try {
             renderInputHandler(inputHandler, outFile, outputFormat);
         } catch (Exception ex) {