Skip to content

Commit 84c8b00

Browse files
committed
Min and max values for range depend on the data type
1 parent 0a5a24c commit 84c8b00

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/main/java/uk/co/jemos/podam/common/BeanValidationStrategy.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,36 @@ public Object getValue(Class<?> attrType, List<Annotation> annotations) throws P
117117

118118
boolean isRound = false;
119119
boolean isFloat = false;
120-
BigDecimal min = new BigDecimal(-Double.MAX_VALUE);
121-
BigDecimal max = new BigDecimal(Double.MAX_VALUE);
120+
BigDecimal min;
121+
BigDecimal max;
122+
if (Long.class.equals(attributeType)
123+
|| long.class.equals(attributeType)) {
124+
125+
min = new BigDecimal(Long.MIN_VALUE);
126+
max = new BigDecimal(Long.MAX_VALUE);
127+
128+
} else if (Integer.class.equals(attributeType)
129+
|| int.class.equals(attributeType)) {
130+
131+
min = new BigDecimal(Integer.MIN_VALUE);
132+
max = new BigDecimal(Integer.MAX_VALUE);
133+
134+
} else if (Short.class.equals(attributeType)
135+
|| short.class.equals(attributeType)) {
136+
137+
min = new BigDecimal(Short.MIN_VALUE);
138+
max = new BigDecimal(Short.MAX_VALUE);
139+
140+
} else if (Byte.class.equals(attributeType)
141+
|| byte.class.equals(attributeType)) {
142+
143+
min = new BigDecimal(Byte.MIN_VALUE);
144+
max = new BigDecimal(Byte.MAX_VALUE);
145+
} else {
146+
147+
min = new BigDecimal(-Double.MAX_VALUE);
148+
max = new BigDecimal(Double.MAX_VALUE);
149+
}
122150

123151
DecimalMin decimalMin = findTypeFromList(annotations, DecimalMin.class);
124152
if (null != decimalMin) {

0 commit comments

Comments
 (0)