-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Guard Values against null/empty values (#1965)
* Guard Values against null/empty values The classes modified by this commit are `DoubleValue`, `LongValue`, and `TimeValue`. Both `null` and empty strings provided to their constructors fail, but they provide very different error messages (NullPointerException and StringIndexOutOfBoundsException), which is neither sensible nor helpful in debugging. This commit adds a guard to throw `IllegalArgumentException` for both cases in order to improve coherency and usefulness of the error messages. * fix checkstyle issues
- Loading branch information
1 parent
67e2204
commit b00322e
Showing
6 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/test/java/net/sf/jsqlparser/expression/DoubleValueTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/*- | ||
* #%L | ||
* JSQLParser library | ||
* %% | ||
* Copyright (C) 2004 - 2019 JSQLParser | ||
* %% | ||
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0 | ||
* #L% | ||
*/ | ||
package net.sf.jsqlparser.expression; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
public class DoubleValueTest { | ||
|
||
@Test | ||
public void testNullValue() { | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
new DoubleValue(null); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testEmptyValue() { | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
new DoubleValue(""); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/test/java/net/sf/jsqlparser/expression/TimeValueTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/*- | ||
* #%L | ||
* JSQLParser library | ||
* %% | ||
* Copyright (C) 2004 - 2019 JSQLParser | ||
* %% | ||
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0 | ||
* #L% | ||
*/ | ||
package net.sf.jsqlparser.expression; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
public class TimeValueTest { | ||
|
||
@Test | ||
public void testNullValue() { | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
new TimeValue(null); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testEmptyValue() { | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
new TimeValue(""); | ||
}); | ||
} | ||
} |