Creating a Java color throws an IllegalArgumentException when used with integer arguments

The following code, executed on some machines of our company, throws an IllegalArgumentException :

 Color sludge = new Color(133, 133, 78); //throws IAE with message "Color parameter outside of expected range: Red Green Blue" 

Instead, an equivalent call works using float arguments:

 Color sludge = new Color(0.522, 0.522, 0.306); // 133/255 = 0.522, 78/255 = 0.306 

Why could this be so? And why does this only affect certain machines?

Perhaps this is due to the fact that these Color objects are defined in Spring as follows:

 <bean id="sludge" class="java.awt.Color"> <constructor-arg value="133"/> <constructor-arg value="133"/> <constructor-arg value="78"/> </bean> 
+4
source share
2 answers

I am NOT an expert with spring. but did you try to set the type to int ?

 <constructor-arg type="int" value="133"> 

?

+3
source

more pedant:

 <bean id="sludge" class="java.awt.Color"> <constructor-arg index="0" type="int"><value>133</value></constructor-arg> <constructor-arg index="1" type="int"><value>133</value></constructor-arg> <constructor-arg index="2" type="int"><value>78</value></constructor-arg> </bean> 

EDIT

check also this blog post

+4
source

All Articles