pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msahy...@apache.org
Subject svn commit: r1826471 - in /pdfbox/trunk: pdfbox/src/main/java/org/apache/pdfbox/cos/ pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/ preflight/src/main/java/org/apache/pdfbox/preflight/process/ preflight/src/main/java/org/apache/pdfbox/preflight/util...
Date Sun, 11 Mar 2018 22:25:45 GMT
Author: msahyoun
Date: Sun Mar 11 22:25:45 2018
New Revision: 1826471

URL: http://svn.apache.org/viewvc?rev=1826471&view=rev
Log:
PDFBOX-4071: remove @throws declaration where exception will not be thrown

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/TrailerValidationProcess.java
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/COSUtils.java
    pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/utils/TestCOSUtils.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java?rev=1826471&r1=1826470&r2=1826471&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java Sun Mar 11 22:25:45
2018
@@ -141,9 +141,8 @@ public class COSDocument extends COSBase
      * @param type The type of the object.
      *
      * @return This will return an object with the specified type.
-     * @throws IOException If there is an error getting the object
      */
-    public COSObject getObjectByType(COSName type)  throws IOException
+    public COSObject getObjectByType(COSName type)
     {
         for( COSObject object : objectPool.values() )
         {
@@ -182,9 +181,8 @@ public class COSDocument extends COSBase
      * @param type The type of the object.
      *
      * @return This will return an object with the specified type.
-     * @throws IOException If there is an error getting the object
      */
-    public List<COSObject> getObjectsByType( String type )  throws IOException
+    public List<COSObject> getObjectsByType( String type )
     {
         return getObjectsByType( COSName.getPDFName( type ) );
     }
@@ -195,9 +193,8 @@ public class COSDocument extends COSBase
      * @param type The type of the object.
      *
      * @return This will return an object with the specified type.
-     * @throws IOException If there is an error getting the object
      */
-    public List<COSObject> getObjectsByType( COSName type )  throws IOException
+    public List<COSObject> getObjectsByType( COSName type )
     {
         List<COSObject> retval = new ArrayList<>();
         for( COSObject object : objectPool.values() )
@@ -521,9 +518,8 @@ public class COSDocument extends COSBase
      * @param key The object key.
      *
      * @return The object in the pool or a new one if it has not been parsed yet.
-     * @throws IOException If there is an error getting the proxy object.
      */
-    public COSObject getObjectFromPool(COSObjectKey key)  throws IOException
+    public COSObject getObjectFromPool(COSObjectKey key)
     {
         COSObject obj = null;
         if( key != null )

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java?rev=1826471&r1=1826470&r2=1826471&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java Sun Mar 11
22:25:45 2018
@@ -251,8 +251,6 @@ public class COSWriter implements ICOSVi
 
     private void prepareIncrement(PDDocument doc)
     {
-      try
-      {
         if (doc != null)
         {
           COSDocument cosDoc = doc.getDocument();
@@ -280,11 +278,6 @@ public class COSWriter implements ICOSVi
           }
           setNumber(highestNumber);
         }
-      }
-      catch (IOException e)
-      {
-          LOG.error(e,e);
-      }
     }
     
     /**

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/TrailerValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/TrailerValidationProcess.java?rev=1826471&r1=1826470&r2=1826471&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/TrailerValidationProcess.java
(original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/TrailerValidationProcess.java
Sun Mar 11 22:25:45 2018
@@ -126,53 +126,46 @@ public class TrailerValidationProcess ex
     protected void checkTrailersForLinearizedPDF15(PreflightContext ctx)
     {
         PDDocument pdfDoc = ctx.getDocument();
-        try
+
+        COSDocument cosDocument = pdfDoc.getDocument();
+        List<COSObject> xrefs = cosDocument.getObjectsByType(COSName.XREF);
+
+        if (xrefs.isEmpty())
+        {
+            // no XRef CosObject, may by this pdf file used the PDF 1.4 syntaxe
+            checkTrailersForLinearizedPDF14(ctx);
+        }
+        else
         {
-            COSDocument cosDocument = pdfDoc.getDocument();
-            List<COSObject> xrefs = cosDocument.getObjectsByType(COSName.XREF);
+            long min = Long.MAX_VALUE;
+            long max = Long.MIN_VALUE;
+            COSDictionary firstTrailer = null;
+            COSDictionary lastTrailer = null;
 
-            if (xrefs.isEmpty())
+            // Search First and Last trailers according to offset position.
+            for (COSObject co : xrefs)
             {
-                // no XRef CosObject, may by this pdf file used the PDF 1.4 syntaxe
-                checkTrailersForLinearizedPDF14(ctx);
-            }
-            else
-            {
-                long min = Long.MAX_VALUE;
-                long max = Long.MIN_VALUE;
-                COSDictionary firstTrailer = null;
-                COSDictionary lastTrailer = null;
-
-                // Search First and Last trailers according to offset position.
-                for (COSObject co : xrefs)
+                long offset = cosDocument.getXrefTable().get(new COSObjectKey(co));
+                if (offset < min)
                 {
-                    long offset = cosDocument.getXrefTable().get(new COSObjectKey(co));
-                    if (offset < min)
-                    {
-                        min = offset;
-                        firstTrailer = (COSDictionary) co.getObject();
-                    }
-
-                    if (offset > max)
-                    {
-                        max = offset;
-                        lastTrailer = (COSDictionary) co.getObject();
-                    }
-
+                    min = offset;
+                    firstTrailer = (COSDictionary) co.getObject();
                 }
 
-                checkMainTrailer(ctx, firstTrailer);
-                if (!compareIds(firstTrailer, lastTrailer, cosDocument))
+                if (offset > max)
                 {
-                    addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_ID_CONSISTENCY,
-                            "ID is different in the first and the last trailer"));
+                    max = offset;
+                    lastTrailer = (COSDictionary) co.getObject();
                 }
+
+            }
+
+            checkMainTrailer(ctx, firstTrailer);
+            if (!compareIds(firstTrailer, lastTrailer, cosDocument))
+            {
+                addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER_ID_CONSISTENCY,
+                        "ID is different in the first and the last trailer"));
             }
-        }
-        catch (IOException e)
-        {
-            addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_SYNTAX_TRAILER,
-                    "Unable to check PDF Trailers: " + e.getMessage(), e));
         }
     }
 

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/COSUtils.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/COSUtils.java?rev=1826471&r1=1826470&r2=1826471&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/COSUtils.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/utils/COSUtils.java Sun
Mar 11 22:25:45 2018
@@ -70,17 +70,10 @@ public final class COSUtils
     {
         if (elt instanceof COSObject)
         {
-            try
-            {
-                COSObjectKey key = new COSObjectKey((COSObject) elt);
-                COSObject obj = doc.getObjectFromPool(key);
-                return (obj != null && (obj.getObject() instanceof COSString || obj.getObject()
instanceof COSName));
-            }
-            catch (IOException e)
-            {
-                LOGGER.debug("Couldn't get COSObject from object pool - returning false",
e);
-                return false;
-            }
+
+            COSObjectKey key = new COSObjectKey((COSObject) elt);
+            COSObject obj = doc.getObjectFromPool(key);
+            return (obj != null && (obj.getObject() instanceof COSString || obj.getObject()
instanceof COSName));
         }
 
         return (elt instanceof COSString || elt instanceof COSName);
@@ -122,17 +115,9 @@ public final class COSUtils
     {
         if (elt instanceof COSObject)
         {
-            try
-            {
-                COSObjectKey key = new COSObjectKey((COSObject) elt);
-                COSObject obj = doc.getObjectFromPool(key);
-                return (obj != null && claz.isInstance(obj.getObject()));
-            }
-            catch (IOException e)
-            {
-                LOGGER.debug("Couldn't get COSObject from object pool - returning false",
e);
-                return false;
-            }
+            COSObjectKey key = new COSObjectKey((COSObject) elt);
+            COSObject obj = doc.getObjectFromPool(key);
+            return (obj != null && claz.isInstance(obj.getObject()));
         }
 
         return claz.isInstance(elt);
@@ -211,28 +196,21 @@ public final class COSUtils
     {
         if (cbase instanceof COSObject)
         {
-            try
+            COSObjectKey key = new COSObjectKey((COSObject) cbase);
+            COSObject obj = cDoc.getObjectFromPool(key);
+            if (obj != null && obj.getObject() instanceof COSString)
             {
-                COSObjectKey key = new COSObjectKey((COSObject) cbase);
-                COSObject obj = cDoc.getObjectFromPool(key);
-                if (obj != null && obj.getObject() instanceof COSString)
-                {
-                    return ((COSString) obj.getObject()).getString();
-                }
-                else if (obj != null && obj.getObject() instanceof COSName)
-                {
-                    return ((COSName) obj.getObject()).getName();
-                }
-                else
-                {
-                    return null;
-                }
+                return ((COSString) obj.getObject()).getString();
             }
-            catch (IOException e)
+            else if (obj != null && obj.getObject() instanceof COSName)
+            {
+                return ((COSName) obj.getObject()).getName();
+            }
+            else
             {
-                LOGGER.debug("Couldn't get COSObject from object pool - returning null",
e);
                 return null;
             }
+
         }
         else if (cbase instanceof COSString)
         {
@@ -308,26 +286,19 @@ public final class COSUtils
     {
         if (cbase instanceof COSObject)
         {
-            try
+
+            COSObjectKey key = new COSObjectKey((COSObject) cbase);
+            COSObject obj = cDoc.getObjectFromPool(key);
+            if (obj == null)
             {
-                COSObjectKey key = new COSObjectKey((COSObject) cbase);
-                COSObject obj = cDoc.getObjectFromPool(key);
-                if (obj == null)
-                {
-                    return null;
-                }
-                else if (obj.getObject() instanceof COSNumber)
-                {
-                    return ((COSNumber) obj.getObject()).floatValue();
-                }
-                else
-                {
-                    return null;
-                }
+                return null;
             }
-            catch (IOException e)
+            else if (obj.getObject() instanceof COSNumber)
+            {
+                return ((COSNumber) obj.getObject()).floatValue();
+            }
+            else
             {
-                LOGGER.debug("Couldn't get COSObject from object pool - returning null",
e);
                 return null;
             }
         }
@@ -353,26 +324,18 @@ public final class COSUtils
     {
         if (cbase instanceof COSObject)
         {
-            try
+            COSObjectKey key = new COSObjectKey((COSObject) cbase);
+            COSObject obj = cDoc.getObjectFromPool(key);
+            if (obj == null)
             {
-                COSObjectKey key = new COSObjectKey((COSObject) cbase);
-                COSObject obj = cDoc.getObjectFromPool(key);
-                if (obj == null)
-                {
-                    return null;
-                }
-                else if (obj.getObject() instanceof COSNumber)
-                {
-                    return ((COSNumber) obj.getObject()).intValue();
-                }
-                else
-                {
-                    return null;
-                }
+                return null;
             }
-            catch (IOException e)
+            else if (obj.getObject() instanceof COSNumber)
+            {
+                return ((COSNumber) obj.getObject()).intValue();
+            }
+            else
             {
-                LOGGER.debug("Couldn't get COSObject from object pool - returning null",
e);
                 return null;
             }
         }
@@ -433,22 +396,14 @@ public final class COSUtils
      */
     private static COSBase getCOSObjectAsClass(COSObject cosObject, COSDocument cDoc, Class
claz)
     {
-        try
+        COSObjectKey key = new COSObjectKey(cosObject);
+        COSObject obj = cDoc.getObjectFromPool(key);
+        if (obj != null && claz.isInstance(obj.getObject()))
         {
-            COSObjectKey key = new COSObjectKey(cosObject);
-            COSObject obj = cDoc.getObjectFromPool(key);
-            if (obj != null && claz.isInstance(obj.getObject()))
-            {
-                return obj.getObject();
-            }
-            else
-            {
-                return null;
-            }
+            return obj.getObject();
         }
-        catch (IOException e)
+        else
         {
-            LOGGER.debug("Couldn't get COSObject from object pool - returning null", e);
             return null;
         }
     }

Modified: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/utils/TestCOSUtils.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/utils/TestCOSUtils.java?rev=1826471&r1=1826470&r2=1826471&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/utils/TestCOSUtils.java
(original)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/utils/TestCOSUtils.java
Sun Mar 11 22:25:45 2018
@@ -233,10 +233,17 @@ public class TestCOSUtils
         }
 
         @Override
-        public COSObject getObjectFromPool(COSObjectKey key) throws IOException
+        public COSObject getObjectFromPool(COSObjectKey key)
         {
-            super.close();
-            throw new IOException("Exception for code coverage");
+            try
+            {
+                super.close();
+            }
+            catch (IOException ioe)
+            {
+                
+            }
+            return null;
         }
     }
 }



Mime
View raw message