jimcoly / h2database

Automatically exported from code.google.com/p/h2database
0 stars 0 forks source link

java.lang.Number not handled in org.h2.value.DataType #536

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi

We had an issue with H2 causing a "org.h2.jdbc.JdbcSQLException: Hexadecimal 
string with odd number of characters ..."

I've analysed the code and found a minory issue in 
  package: org.h2.value
  Class: DataType
  Method: public static Value getTypeFromClass(Class <?> x)
  H2 Version: 1.3.172 (guess it's also in the newest version)

Issue:
  We added a function to H2 with a parameter of type java.lang.Number that is not handled in the if-then-else of the method mentiond above.

Think the it should be handled correctly or at least a the exception should be 
more sensable :-)

Regards Sam 

Original issue reported on code.google.com by 2mat...@gmail.com on 9 Dec 2013 at 4:13

GoogleCodeExporter commented 9 years ago
Hm, how should it be handled?

Original comment by thomas.t...@gmail.com on 9 Dec 2013 at 6:12

GoogleCodeExporter commented 9 years ago
Thank you for you answer.

I think there are 2 possable solution:

a) A less missleading Exception message would be good. Currently 
getTypeFromClass() returns a Value.JAVA_OBJECT if no matching class can be 
found. This leads to the assumption in H2 that it must be a Hexadecimal string 
(I didn't investigate why this should be assumed). The Exception should contain 
the x.getClass().getSimpleName() and some info that it was unable to handle 
that type.

OR 
b) assume Number as a valid class

   if (Number.class.isAssignableFrom(x)) {
      return  Value.DECIMAL // or return Value.NUMBER
   }

I pefer a). A clean Exception output (programmer then able to understand that 
he must use a different class). If there is still demand to support other 
classes in getTypeFromClass() then this can be done later.

Cheers Sam 

Original comment by 2mat...@gmail.com on 9 Dec 2013 at 11:47

GoogleCodeExporter commented 9 years ago
Hi,

I don't quite understand the use case... Could you post some code that shows 
how this would be used?

Thanks!

Original comment by thomas.t...@gmail.com on 12 Dec 2013 at 4:28

GoogleCodeExporter commented 9 years ago
Hi Sam,

I understand that you want to create a function that can take any kind of 
numeric value (int or double for exemple); as overload require different number 
of parameters you could use as parameter the object org.h2.value.Value instead 
of using Numeric then check inside your function the parameter.

-Nicolas
Atelier SIG
IRSTV FR CNRS 2488

Original comment by fnicola...@gmail.com on 14 Dec 2013 at 10:11

GoogleCodeExporter commented 9 years ago
OK, I think I understand now. Yes, a better error message would be nice. 
Patches are welcome!

Original comment by thomas.t...@gmail.com on 14 Dec 2013 at 12:49

GoogleCodeExporter commented 9 years ago
Hi
thanks for all the great feedback !
I think I can send you a patch suggestion that will produce a more sensible
Expedition next week.
Chears Sam
Am 14.12.2013 13:50 schrieb <h2database@googlecode.com>:

Original comment by 2mat...@gmail.com on 14 Dec 2013 at 1:04