[bug-65741] change some methods to throw checked exception InvalidFormatException

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895882 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2021-12-13 13:52:46 +00:00
parent 837590024f
commit 469a485f38
3 changed files with 20 additions and 26 deletions

View File

@ -276,7 +276,7 @@ public class POIXMLProperties {
public void setCreated(Optional<Date> date) {
part.setCreatedProperty(date);
}
public void setCreated(String date) {
public void setCreated(String date) throws InvalidFormatException {
part.setCreatedProperty(date);
}
public String getCreator() {
@ -309,7 +309,7 @@ public class POIXMLProperties {
public void setLastPrinted(Optional<Date> date) {
part.setLastPrintedProperty(date);
}
public void setLastPrinted(String date) {
public void setLastPrinted(String date) throws InvalidFormatException {
part.setLastPrintedProperty(date);
}
/** @since POI 3.15 beta 3 */
@ -326,7 +326,7 @@ public class POIXMLProperties {
public void setModified(Optional<Date> date) {
part.setModifiedProperty(date);
}
public void setModified(String date) {
public void setModified(String date) throws InvalidFormatException {
part.setModifiedProperty(date);
}
public String getSubject() {

View File

@ -17,6 +17,8 @@
package org.apache.poi.openxml4j.opc;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import java.util.Date;
import java.util.Optional;
@ -102,8 +104,10 @@ public interface PackageProperties {
/**
* Set the date of creation of the resource.
* @throws InvalidFormatException only since POI 5.2.0, used to throw unchecked exception
* IllegalArgumentException if format was invalid
*/
void setCreatedProperty(String created);
void setCreatedProperty(String created) throws InvalidFormatException;
/**
* Set the date of creation of the resource.
@ -227,8 +231,10 @@ public interface PackageProperties {
/**
* Set the date and time of the last printing.
* @throws InvalidFormatException only since POI 5.2.0, used to throw unchecked exception
* IllegalArgumentException if format was invalid
*/
void setLastPrintedProperty(String lastPrinted);
void setLastPrintedProperty(String lastPrinted) throws InvalidFormatException;
/**
* Set the date and time of the last printing.
@ -243,8 +249,10 @@ public interface PackageProperties {
/**
* Set the date on which the resource was changed.
* @throws InvalidFormatException only since POI 5.2.0, used to throw unchecked exception
* IllegalArgumentException if format was invalid
*/
void setModifiedProperty(String modified);
void setModifiedProperty(String modified) throws InvalidFormatException;
/**
* Set the date on which the resource was changed.

View File

@ -427,12 +427,8 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP
* @see org.apache.poi.openxml4j.opc.PackageProperties#setCreatedProperty(java.util.Optional)
*/
@Override
public void setCreatedProperty(String created) {
try {
this.created = parseDateValue(created);
} catch (InvalidFormatException e) {
throw new IllegalArgumentException("Date for created could not be parsed: " + created, e);
}
public void setCreatedProperty(String created) throws InvalidFormatException {
this.created = parseDateValue(created);
}
/**
@ -548,13 +544,8 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP
* @see org.apache.poi.openxml4j.opc.PackageProperties#setLastPrintedProperty(java.util.Optional)
*/
@Override
public void setLastPrintedProperty(String lastPrinted) {
try {
this.lastPrinted = parseDateValue(lastPrinted);
} catch (InvalidFormatException e) {
throw new IllegalArgumentException("lastPrinted : "
+ e.getLocalizedMessage(), e);
}
public void setLastPrintedProperty(String lastPrinted) throws InvalidFormatException {
this.lastPrinted = parseDateValue(lastPrinted);
}
/**
@ -572,13 +563,8 @@ public final class PackagePropertiesPart extends PackagePart implements PackageP
* @see org.apache.poi.openxml4j.opc.PackageProperties#setModifiedProperty(java.util.Optional)
*/
@Override
public void setModifiedProperty(String modified) {
try {
this.modified = parseDateValue(modified);
} catch (InvalidFormatException e) {
throw new IllegalArgumentException("modified : "
+ e.getLocalizedMessage(), e);
}
public void setModifiedProperty(String modified) throws InvalidFormatException {
this.modified = parseDateValue(modified);
}
/**