Skip to content

Commit

Permalink
move InvalidArgumentException to IllegalArgumentException (#861)
Browse files Browse the repository at this point in the history
This breaks backward compatibility.
  • Loading branch information
balamurugana authored Mar 8, 2020
1 parent 095285f commit 9c9f2d1
Show file tree
Hide file tree
Showing 19 changed files with 185 additions and 240 deletions.
29 changes: 14 additions & 15 deletions api/src/main/java/io/minio/ComposeSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import java.util.Map;
import java.util.TreeMap;
import io.minio.errors.InvalidArgumentException;
import io.minio.CopyConditions;

public class ComposeSource {
Expand All @@ -36,56 +35,56 @@ public class ComposeSource {
/**
* Create new ComposeSource for given bucket and object.
*/
public ComposeSource(String bucketName, String objectName) throws InvalidArgumentException {
public ComposeSource(String bucketName, String objectName) throws IllegalArgumentException {
this(bucketName, objectName, null, null, null, null, null);
}

/**
* Create new ComposeSource for given bucket, object, offset and length.
*/
public ComposeSource(String bucketName, String objectName, Long offset, Long length)
throws InvalidArgumentException {
throws IllegalArgumentException {
this(bucketName, objectName, offset, length, null, null, null);
}

/**
* Create new ComposeSource for given bucket, object, offset, length and headerMap.
*/
public ComposeSource(String bucketName, String objectName, Long offset, Long length,
Map<String, String> headerMap) throws InvalidArgumentException {
Map<String, String> headerMap) throws IllegalArgumentException {
this(bucketName, objectName, offset, length, headerMap, null, null);
}

/**
* Create new ComposeSource for given bucket, object, offset, length, headerMap and CopyConditions.
*/
public ComposeSource(String bucketName, String objectName, Long offset, Long length,
Map<String, String> headerMap, CopyConditions copyConditions) throws InvalidArgumentException {
Map<String, String> headerMap, CopyConditions copyConditions) throws IllegalArgumentException {
this(bucketName, objectName, offset, length, headerMap, copyConditions, null);
}

/**
* Creates new ComposeSource for given bucket, object, offset, length, headerMap, CopyConditions
* and server side encryption.
*
* @throws InvalidArgumentException upon invalid value is passed to a method.
* @throws IllegalArgumentException upon invalid value is passed to a method.
*/
public ComposeSource(String bucketName, String objectName, Long offset, Long length, Map<String, String> headerMap,
CopyConditions copyConditions, ServerSideEncryption sse) throws InvalidArgumentException {
CopyConditions copyConditions, ServerSideEncryption sse) throws IllegalArgumentException {
if (bucketName == null) {
throw new InvalidArgumentException("Source bucket name cannot be empty");
throw new IllegalArgumentException("Source bucket name cannot be empty");
}

if (objectName == null) {
throw new InvalidArgumentException("Source object name cannot be empty");
throw new IllegalArgumentException("Source object name cannot be empty");
}

if (offset != null && offset < 0) {
throw new InvalidArgumentException("Offset cannot be negative");
throw new IllegalArgumentException("Offset cannot be negative");
}

if (length != null && length < 0) {
throw new InvalidArgumentException("Length cannot be negative");
throw new IllegalArgumentException("Length cannot be negative");
}

if (length != null && offset == null) {
Expand All @@ -105,20 +104,20 @@ public ComposeSource(String bucketName, String objectName, Long offset, Long len
* Constructs header .
*
*/
public void buildHeaders(long objectSize, String etag) throws InvalidArgumentException {
public void buildHeaders(long objectSize, String etag) throws IllegalArgumentException {
if (offset != null && offset >= objectSize) {
throw new InvalidArgumentException("source " + bucketName + "/" + objectName + ": offset " + offset
throw new IllegalArgumentException("source " + bucketName + "/" + objectName + ": offset " + offset
+ " is beyond object size " + objectSize);
}

if (length != null) {
if (length > objectSize) {
throw new InvalidArgumentException("source " + bucketName + "/" + objectName + ": length " + length
throw new IllegalArgumentException("source " + bucketName + "/" + objectName + ": length " + length
+ " is beyond object size " + objectSize);
}

if (offset + length > objectSize) {
throw new InvalidArgumentException("source " + bucketName + "/" + objectName + ": compose size "
throw new IllegalArgumentException("source " + bucketName + "/" + objectName + ": compose size "
+ (offset + length) + " is beyond object size " + objectSize);
}
}
Expand Down
25 changes: 12 additions & 13 deletions api/src/main/java/io/minio/CopyConditions.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package io.minio;

import io.minio.errors.InvalidArgumentException;
import io.minio.Time;
import java.time.ZonedDateTime;
import java.util.Collections;
Expand All @@ -38,12 +37,12 @@ public class CopyConditions {
/**
* Set modified condition, copy object modified since given time.
*
* @throws InvalidArgumentException
* @throws IllegalArgumentException
* When date is null
*/
public void setModified(ZonedDateTime time) throws InvalidArgumentException {
public void setModified(ZonedDateTime time) throws IllegalArgumentException {
if (time == null) {
throw new InvalidArgumentException("modified time cannot be empty");
throw new IllegalArgumentException("modified time cannot be empty");
}
copyConditions.put("x-amz-copy-source-if-modified-since",
time.format(Time.HTTP_HEADER_DATE_FORMAT));
Expand All @@ -52,12 +51,12 @@ public void setModified(ZonedDateTime time) throws InvalidArgumentException {
/**
* Sets object unmodified condition, copy object unmodified since given time.
*
* @throws InvalidArgumentException
* @throws IllegalArgumentException
* When date is null
*/
public void setUnmodified(ZonedDateTime time) throws InvalidArgumentException {
public void setUnmodified(ZonedDateTime time) throws IllegalArgumentException {
if (time == null) {
throw new InvalidArgumentException("unmodified time can not be null");
throw new IllegalArgumentException("unmodified time can not be null");
}

copyConditions.put("x-amz-copy-source-if-unmodified-since",
Expand All @@ -68,12 +67,12 @@ public void setUnmodified(ZonedDateTime time) throws InvalidArgumentException {
* Set matching ETag condition, copy object which matches
* the following ETag.
*
* @throws InvalidArgumentException
* @throws IllegalArgumentException
* When etag is null
*/
public void setMatchETag(String etag) throws InvalidArgumentException {
public void setMatchETag(String etag) throws IllegalArgumentException {
if (etag == null) {
throw new InvalidArgumentException("ETag cannot be empty");
throw new IllegalArgumentException("ETag cannot be empty");
}
copyConditions.put("x-amz-copy-source-if-match", etag);
}
Expand All @@ -82,12 +81,12 @@ public void setMatchETag(String etag) throws InvalidArgumentException {
* Set matching ETag none condition, copy object which does not
* match the following ETag.
*
* @throws InvalidArgumentException
* @throws IllegalArgumentException
* When etag is null
*/
public void setMatchETagNone(String etag) throws InvalidArgumentException {
public void setMatchETagNone(String etag) throws IllegalArgumentException {
if (etag == null) {
throw new InvalidArgumentException("ETag cannot be empty");
throw new IllegalArgumentException("ETag cannot be empty");
}
copyConditions.put("x-amz-copy-source-if-none-match", etag);
}
Expand Down
Loading

0 comments on commit 9c9f2d1

Please sign in to comment.