Skip to content

Commit 349a8bd

Browse files
author
lucaijun
committed
AJ-447: fix negative number build month
1 parent d0c3fd3 commit 349a8bd

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/com/xxdb/data/BasicMonth.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.xxdb.io.ExtendedDataInput;
44

55
import java.io.IOException;
6+
import java.time.DateTimeException;
67
import java.time.Month;
78
import java.time.YearMonth;
89
import java.time.format.DateTimeFormatter;
@@ -19,6 +20,8 @@ public class BasicMonth extends BasicInt{
1920

2021
public BasicMonth(int year, Month month){
2122
super(year * 12 + month.getValue()-1);
23+
if (getInt() < 0)
24+
throw new DateTimeException(String.format("year %d is invalid, it must be non-negative integer", year));
2225
}
2326
public BasicMonth(Calendar calendar){
2427
super((calendar.get(Calendar.YEAR)) * 12 + calendar.get(Calendar.MONTH));
@@ -33,6 +36,8 @@ public BasicMonth(ExtendedDataInput in) throws IOException {
3336

3437
protected BasicMonth(int value){
3538
super(value);
39+
if (getInt() < 0)
40+
throw new DateTimeException(String.format("number %d is invalid, it must be non-negative integer", getInt()));
3641
}
3742

3843

0 commit comments

Comments
 (0)