From 45c10d5cb2b002d6d3a063ebe0b51d39e102de05 Mon Sep 17 00:00:00 2001 From: Imran M Yousuf Date: Mon, 23 Mar 2009 12:37:37 +0600 Subject: [PATCH] Fix content disposition construction with null name argument Despite 2 constructors ensuring that 'name' is a mandatory parameter the all arguments constructor does not respect it and the builder also does not respect it. This change fixes this behavior and ensures conherence. This builder was internally being used from FormDataBodyPart where if null name was being set it used to create a content disposition which was not supposed to be there. This change also fixes that and encapsulates the build statements from exceptions in the builder. Signed-off-by: Imran M Yousuf --- .../com/sun/jersey/multipart/FormDataBodyPart.java | 10 +++++++++- .../core/header/FormDataContentDisposition.java | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletions(-) diff --git a/contribs/jersey-multipart/src/main/java/com/sun/jersey/multipart/FormDataBodyPart.java b/contribs/jersey-multipart/src/main/java/com/sun/jersey/multipart/FormDataBodyPart.java index 3b9317b..75d7bcd 100644 --- a/contribs/jersey-multipart/src/main/java/com/sun/jersey/multipart/FormDataBodyPart.java +++ b/contribs/jersey-multipart/src/main/java/com/sun/jersey/multipart/FormDataBodyPart.java @@ -241,7 +241,15 @@ public class FormDataBodyPart extends BodyPart { */ public void setName(String name) { if (getFormDataContentDisposition() == null) { - super.setContentDisposition(FormDataContentDisposition.name(name).build()); + FormDataContentDisposition contentDisposition; + try { + contentDisposition = FormDataContentDisposition.name(name) + .build(); + } + catch(Exception ex) { + contentDisposition = null; + } + super.setContentDisposition(contentDisposition); } else { FormDataContentDisposition cd = getFormDataContentDisposition(); cd = FormDataContentDisposition.name(name). diff --git a/jersey-core/src/main/java/com/sun/jersey/core/header/FormDataContentDisposition.java b/jersey-core/src/main/java/com/sun/jersey/core/header/FormDataContentDisposition.java index 0f3c73c..f1d524d 100644 --- a/jersey-core/src/main/java/com/sun/jersey/core/header/FormDataContentDisposition.java +++ b/jersey-core/src/main/java/com/sun/jersey/core/header/FormDataContentDisposition.java @@ -65,6 +65,12 @@ public class FormDataContentDisposition extends ContentDisposition { long size) { super(type, fileName, creationDate, modificationDate, readDate, size); this.name = name; + if (!getType().equals("form-data")) { + throw new IllegalArgumentException("The content dispostion type is not equal to form-data"); + } + if (name == null) { + throw new IllegalArgumentException("The name parameter is not present"); + } } public FormDataContentDisposition(String header) throws ParseException { @@ -108,6 +114,9 @@ public class FormDataContentDisposition extends ContentDisposition { * @return the form data content disposition builder. */ public static FormDataContentDispositionBuilder name(String name) { + if(name == null) { + throw new IllegalArgumentException("The name parameter is not present"); + } return new FormDataContentDispositionBuilder(name); } -- 1.5.6