Skip to content
Permalink
Browse files

8239520: ValueRange.of(long, long, long) does not throw IAE on invali…

…d inputs

Reviewed-by: rriggs
  • Loading branch information
Naoto Sato
Naoto Sato committed Feb 24, 2020
1 parent c30f845 commit 8493812702a93101026b7f02ae60bf788d5c9309
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -145,6 +145,9 @@ public static ValueRange of(long min, long max) {
* or the smallest maximum is greater than the largest maximum
*/
public static ValueRange of(long min, long maxSmallest, long maxLargest) {
if (min > maxSmallest) {
throw new IllegalArgumentException("Minimum value must be less than smallest maximum value");
}
return of(min, min, maxSmallest, maxLargest);
}

@@ -160,8 +163,9 @@ public static ValueRange of(long min, long maxSmallest, long maxLargest) {
* @return the ValueRange for smallest min, largest min, smallest max, largest max, not null
* @throws IllegalArgumentException if
* the smallest minimum is greater than the smallest maximum,
* or the smallest maximum is greater than the largest maximum
* or the largest minimum is greater than the largest maximum
* or the smallest maximum is greater than the largest maximum,
* or the largest minimum is greater than the largest maximum,
* or the smallest minimum is greater than the largest minimum
*/
public static ValueRange of(long minSmallest, long minLargest, long maxSmallest, long maxLargest) {
if (minSmallest > minLargest) {
@@ -171,7 +175,10 @@ public static ValueRange of(long minSmallest, long minLargest, long maxSmallest,
throw new IllegalArgumentException("Smallest maximum value must be less than largest maximum value");
}
if (minLargest > maxLargest) {
throw new IllegalArgumentException("Minimum value must be less than maximum value");
throw new IllegalArgumentException("Largest minimum value must be less than largest maximum value");
}
if (minSmallest > maxSmallest) {
throw new IllegalArgumentException("Smallest minimum value must be less than smallest maximum value");
}
return new ValueRange(minSmallest, minLargest, maxSmallest, maxLargest);
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -75,6 +75,7 @@

/**
* Test.
* @bug 8239520
*/
@Test
public class TestDateTimeValueRange extends AbstractTest {
@@ -138,6 +139,11 @@ public void test_of_longlonglong_smallestmaxminGtMax() {
ValueRange.of(1, 31, 28);
}

@Test(expectedExceptions = IllegalArgumentException.class)
public void test_of_longlonglong_minGtSmallestMax() {
ValueRange.of(5, 2, 10);
}

//-----------------------------------------------------------------------
// of(long,long,long,long)
//-----------------------------------------------------------------------
@@ -178,6 +184,11 @@ public void test_of_longlonglonglong(long sMin, long lMin, long sMax, long lMax)
{2, 1, 28, 31},
{2, 1, 31, 28},
{12, 13, 1, 2},

{10, 11, 0, 12}, // smallest minimum is greater than the smallest maximum
{0, 1, 11, 10}, // smallest maximum is greater than the largest maximum
{0, 11, 1, 10}, // largest minimum is greater than the largest maximum
{1, 0, 10, 11}, // smallest minimum is greater than the largest minimum
};
}

0 comments on commit 8493812

Please sign in to comment.