Index: pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/TestEmbeddedFiles.java
===================================================================
--- pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/TestEmbeddedFiles.java	(revision 0)
+++ pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/TestEmbeddedFiles.java	(revision 0)
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.pdmodel.common;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
+import org.apache.pdfbox.pdmodel.PDDocumentNameDictionary;
+import org.apache.pdfbox.pdmodel.PDEmbeddedFilesNameTreeNode;
+import org.apache.pdfbox.pdmodel.TestPDDocumentCatalog;
+import org.apache.pdfbox.pdmodel.common.filespecification.PDComplexFileSpecification;
+import org.apache.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile;
+import org.junit.Test;
+
+import junit.framework.TestCase;
+
+public class TestEmbeddedFiles extends TestCase {
+
+    @Test
+    public void testNullEmbeddedFile() throws IOException{
+        PDDocument doc = null;
+        PDEmbeddedFile targEF = null;
+        boolean gotten = false;
+        try {
+            doc = PDDocument.load(TestPDDocumentCatalog.class.getResourceAsStream("test_null_PDComplexFileSpecification.pdf"));
+            PDDocumentCatalog catalog = doc.getDocumentCatalog();
+            PDDocumentNameDictionary names = catalog.getNames();
+            assertEquals("should be two files in dict", 2, names.getEmbeddedFiles().getNames().size());
+            PDEmbeddedFilesNameTreeNode embeddedFiles = names.getEmbeddedFiles();
+
+            PDComplexFileSpecification spec = (PDComplexFileSpecification)embeddedFiles.getNames().get("non-existent-file.docx");
+            if (spec != null){
+                targEF = spec.getEmbeddedFile();
+                gotten = true;
+            }
+            //now test for actual attachment
+            spec = (PDComplexFileSpecification)embeddedFiles.getNames().get("My first attachment");
+            assertNotNull("one attachment actually exists", spec);
+            assertEquals("existing file length", 17660, spec.getEmbeddedFile().getLength());
+            spec = (PDComplexFileSpecification)embeddedFiles.getNames().get("non-existent-file.docx");
+
+        } catch (NullPointerException e){
+            assertNotNull("null pointer exception", null);
+        }
+        assertTrue("Was able to get file without exception", gotten);
+        assertNull("EmbeddedFile was correctly null", targEF);
+    }
+
+}
+
Index: pdfbox/src/test/resources/org/apache/pdfbox/pdmodel/test_null_PDComplexFileSpecification.pdf
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: pdfbox/src/test/resources/org/apache/pdfbox/pdmodel/test_null_PDComplexFileSpecification.pdf
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Index: pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/filespecification/PDComplexFileSpecification.java
===================================================================
--- pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/filespecification/PDComplexFileSpecification.java	(revision 1564433)
+++ pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/filespecification/PDComplexFileSpecification.java	(working copy)
@@ -41,13 +41,18 @@
     }
 
     /**
-     * Constructor.
+     * Constructor. Creates empty COSDictionary if dict is null.
      *
      * @param dict The dictionary that fulfils this file specification.
      */
     public PDComplexFileSpecification( COSDictionary dict )
     {
-        fs = dict;
+        if (dict == null){
+            fs = new COSDictionary();
+            fs.setItem( COSName.TYPE, COSName.FILESPEC );
+        } else {
+            fs = dict;
+        }
     }
 
     /**
Index: pdfbox/src/main/java/org/apache/pdfbox/ExtractText.java
===================================================================
--- pdfbox/src/main/java/org/apache/pdfbox/ExtractText.java	(revision 1564433)
+++ pdfbox/src/main/java/org/apache/pdfbox/ExtractText.java	(working copy)
@@ -292,7 +292,7 @@
                                 }
                                 PDComplexFileSpecification spec = (PDComplexFileSpecification) ent.getValue();
                                 PDEmbeddedFile file = spec.getEmbeddedFile();
-                                if (file.getSubtype().equals("application/pdf")) 
+                                if (file != null && file.getSubtype().equals("application/pdf")) 
                                 {
                                     if (debug)
                                     {
