Skip to content

Commit

Permalink
Port to Java 1.4 Throwable APIs (!)
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Oct 10, 2024
1 parent 4699a8b commit 0604791
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 77 deletions.
1 change: 1 addition & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory">Remove unused exception from FileUploadBase.createItem(Map, boolean).</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Migrate from deprecated API in DiskFileItem.getOutputStream().</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Use try-with-resources.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Port to Java 1.4 Throwable APIs (!).</action>
<!-- UPDATE -->
<action dev="ggregory" type="update">Bump Java from 6 to 8.</action>
<action dev="ggregory" type="update">Bump commons-parent from 62 to 76.</action>
Expand Down
32 changes: 7 additions & 25 deletions src/main/java/org/apache/commons/fileupload/FileUploadBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -662,13 +662,13 @@ public InvalidContentTypeException(final String message) {
* Constructs an {@code InvalidContentTypeException} with
* the specified detail message and cause.
*
* @param msg The detail message.
* @param message The detail message.
* @param cause the original cause
*
* @since 1.3.1
*/
public InvalidContentTypeException(final String msg, final Throwable cause) {
super(msg, cause);
public InvalidContentTypeException(final String message, final Throwable cause) {
super(message, cause);
}
}

Expand All @@ -682,32 +682,14 @@ public static class IOFileUploadException extends FileUploadException {
*/
private static final long serialVersionUID = 1749796615868477269L;

/**
* The exceptions cause; we overwrite the parent
* classes field, which is available since Java
* 1.4 only.
*/
private final IOException cause;

/**
* Creates a new instance with the given cause.
*
* @param pMsg The detail message.
* @param pException The exceptions cause.
*/
public IOFileUploadException(final String pMsg, final IOException pException) {
super(pMsg);
cause = pException;
}

/**
* Returns the exceptions cause.
*
* @return The exceptions cause, if any, or null.
* @param message The detail message.
* @param cause The exceptions cause.
*/
@Override
public Throwable getCause() {
return cause;
public IOFileUploadException(final String message, final IOException cause) {
super(message, cause);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
*/
package org.apache.commons.fileupload;

import java.io.PrintStream;
import java.io.PrintWriter;

/**
* Exception for errors encountered while processing the request.
*/
Expand All @@ -30,74 +27,32 @@ public class FileUploadException extends Exception {
*/
private static final long serialVersionUID = 8881893724388807504L;

/**
* The exceptions cause. We overwrite the cause of
* the super class, which isn't available in Java 1.3.
*/
private final Throwable cause;

/**
* Constructs a new {@code FileUploadException} without message.
*/
public FileUploadException() {
this(null, null);
// empty
}

/**
* Constructs a new {@code FileUploadException} with specified detail
* message.
*
* @param msg the error message.
* @param message the error message.
*/
public FileUploadException(final String msg) {
this(msg, null);
public FileUploadException(final String message) {
super(message);
}

/**
* Creates a new {@code FileUploadException} with the given
* detail message and cause.
*
* @param msg The exceptions detail message.
* @param message The exceptions detail message.
* @param cause The exceptions cause.
*/
public FileUploadException(final String msg, final Throwable cause) {
super(msg);
this.cause = cause;
}

@SuppressWarnings("sync-override")
@Override
public Throwable getCause() {
return cause;
}

/**
* Prints this throwable and its backtrace to the specified print stream.
*
* @param stream {@code PrintStream} to use for output
*/
@Override
public void printStackTrace(final PrintStream stream) {
super.printStackTrace(stream);
if (cause != null) {
stream.println("Caused by:");
cause.printStackTrace(stream);
}
}

/**
* Prints this throwable and its backtrace to the specified
* print writer.
*
* @param writer {@code PrintWriter} to use for output
*/
@Override
public void printStackTrace(final PrintWriter writer) {
super.printStackTrace(writer);
if (cause != null) {
writer.println("Caused by:");
cause.printStackTrace(writer);
}
public FileUploadException(final String message, final Throwable cause) {
super(message, cause);
}

}

0 comments on commit 0604791

Please sign in to comment.