You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Kevin Jackson (JIRA)" <ji...@apache.org> on 2010/11/23 06:59:13 UTC

[jira] Created: (PDFBOX-901) NPE in importPage() when importing a blank page (No Contents item)

NPE in importPage() when importing a blank page (No Contents item)
------------------------------------------------------------------

                 Key: PDFBOX-901
                 URL: https://issues.apache.org/jira/browse/PDFBOX-901
             Project: PDFBox
          Issue Type: Bug
          Components: PDModel
    Affects Versions: 1.3.1
            Reporter: Kevin Jackson


Null Pointer Exception importing a page if the page does not have a Contents item.  (A blank page)
Patch is to not try to copy Contents.


### Eclipse Workspace Patch 1.0
#P pdfbox
Index: pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
===================================================================
--- pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java	(revision 1026306)
+++ pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java	(working copy)
@@ -322,16 +322,19 @@
         try
         {
             PDStream src = page.getContents();
-            PDStream dest = new PDStream( new COSStream( src.getStream(), document.getScratchFile() ) );
-            importedPage.setContents( dest );
-            os = dest.createOutputStream();
+            if (src != null)
+            {
+                PDStream dest = new PDStream( new COSStream( src.getStream(), document.getScratchFile() ) );
+                importedPage.setContents( dest );
+                os = dest.createOutputStream();
 
-            byte[] buf = new byte[10240];
-            int amountRead = 0;
-            is = src.createInputStream();
-            while((amountRead = is.read(buf,0,10240)) > -1)
-            {
-                os.write(buf, 0, amountRead);
+                byte[] buf = new byte[10240];
+                int amountRead = 0;
+                is = src.createInputStream();
+                while((amountRead = is.read(buf,0,10240)) > -1)
+                {
+                    os.write(buf, 0, amountRead);
+                }
             }
             addPage( importedPage );
         }


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (PDFBOX-901) NPE in importPage() when importing a blank page (No Contents item)

Posted by "Kevin Jackson (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/PDFBOX-901?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Kevin Jackson closed PDFBOX-901.
--------------------------------

    Resolution: Duplicate

Duplicate of PDFBOX-889

> NPE in importPage() when importing a blank page (No Contents item)
> ------------------------------------------------------------------
>
>                 Key: PDFBOX-901
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-901
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 1.3.1
>            Reporter: Kevin Jackson
>
> Null Pointer Exception importing a page if the page does not have a Contents item.  (A blank page)
> Patch is to not try to copy Contents.
> ### Eclipse Workspace Patch 1.0
> #P pdfbox
> Index: pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
> ===================================================================
> --- pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java	(revision 1026306)
> +++ pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java	(working copy)
> @@ -322,16 +322,19 @@
>          try
>          {
>              PDStream src = page.getContents();
> -            PDStream dest = new PDStream( new COSStream( src.getStream(), document.getScratchFile() ) );
> -            importedPage.setContents( dest );
> -            os = dest.createOutputStream();
> +            if (src != null)
> +            {
> +                PDStream dest = new PDStream( new COSStream( src.getStream(), document.getScratchFile() ) );
> +                importedPage.setContents( dest );
> +                os = dest.createOutputStream();
>  
> -            byte[] buf = new byte[10240];
> -            int amountRead = 0;
> -            is = src.createInputStream();
> -            while((amountRead = is.read(buf,0,10240)) > -1)
> -            {
> -                os.write(buf, 0, amountRead);
> +                byte[] buf = new byte[10240];
> +                int amountRead = 0;
> +                is = src.createInputStream();
> +                while((amountRead = is.read(buf,0,10240)) > -1)
> +                {
> +                    os.write(buf, 0, amountRead);
> +                }
>              }
>              addPage( importedPage );
>          }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.