diff --git a/simple/simple-http/src/main/java/org/simpleframework/http/message/BufferPart.java b/simple/simple-http/src/main/java/org/simpleframework/http/message/BufferPart.java index 73a5ea0..b1d2d48 100644 --- a/simple/simple-http/src/main/java/org/simpleframework/http/message/BufferPart.java +++ b/simple/simple-http/src/main/java/org/simpleframework/http/message/BufferPart.java @@ -69,7 +69,11 @@ public BufferPart(Segment segment, Buffer buffer) { * @return this returns true if the associated part is a file */ public boolean isFile() { - return getDisposition().isFile(); + ContentDisposition disposition = getDisposition(); + if (disposition == null) { + return false; + } + return disposition.isFile(); } /** @@ -80,7 +84,11 @@ public boolean isFile() { * @return this returns the name of the associated part */ public String getName() { - return getDisposition().getName(); + ContentDisposition disposition = getDisposition(); + if (disposition == null) { + return null; + } + return disposition.getName(); } /** @@ -91,7 +99,11 @@ public String getName() { * @return this returns the file name of the associated part */ public String getFileName() { - return getDisposition().getFileName(); + ContentDisposition disposition = getDisposition(); + if (disposition == null) { + return null; + } + return disposition.getFileName(); } /** diff --git a/simple/simple-http/src/test/java/org/simpleframework/http/message/BufferPartTest.java b/simple/simple-http/src/test/java/org/simpleframework/http/message/BufferPartTest.java new file mode 100644 index 0000000..7be8396 --- /dev/null +++ b/simple/simple-http/src/test/java/org/simpleframework/http/message/BufferPartTest.java @@ -0,0 +1,14 @@ +package org.simpleframework.http.message; + +import junit.framework.TestCase; +import org.simpleframework.common.buffer.ArrayAllocator; + +public class BufferPartTest extends TestCase { + + public void testNoDispositionContextNPE() throws Exception { + BufferPart bufferPart = new BufferPart(new MockSegment(), new ArrayAllocator().allocate()); + assertNull(bufferPart.getFileName()); + assertNull(bufferPart.getName()); + assertFalse(bufferPart.isFile()); + } +}