youxinren / snakeyaml

Automatically exported from code.google.com/p/snakeyaml
Apache License 2.0
0 stars 0 forks source link

ClassCastException in Representer #64

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

In my project I serialize lists of Class Objects (List<Class<Object>> for 
example). I wrote a Representer for Class Objects. If I try to dump such 
a list I get a ClassCastException within the Representer.

Exception in thread "main" java.lang.ClassCastException: 
sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be 
cast to java.lang.Class
    at 
org.yaml.snakeyaml.representer.Representer.checkGlobalTag(Representer.java
:184)

You can avoid this exception with the following code (Representer 184):

Class<? extends Object> t;
if (arguments[0] instanceof ParameterizedType) {
    t = (Class<? extends Object>) ((ParameterizedType) 
arguments[0]).getRawType();
} else {
    t = (Class<? extends Object>) arguments[0];
}

The same exception occurs in the Constructor on line 280.

I hope this will help to improve this nice tool.

Kind regards
Maxim

Original issue reported on code.google.com by maxim.mo...@googlemail.com on 18 Apr 2010 at 5:08

GoogleCodeExporter commented 9 years ago
Can you please provide a test to reproduce the problem ? What is the version ? 
Have you 
tried the latest source ?

It seems to be related to issue 61. But I am afraid your business case covers 
more then 
it is done for issue 61.

Original comment by py4fun@gmail.com on 19 Apr 2010 at 10:29

GoogleCodeExporter commented 9 years ago
Hey py4fun,

as you wished I wrote a small test which reproduces the exception. I tested the 
unit
test with version 1.6. But the same happens in the current source, too.

Kind regards
Maxim

Original comment by maxim.mo...@googlemail.com on 25 Apr 2010 at 8:29

Attachments:

GoogleCodeExporter commented 9 years ago
Thank you. The bug was identified and fixed. Please check the latest source.

http://code.google.com/p/snakeyaml/source/detail?r=7056861197fa30b1d4872d533fb22
5bbef4b80f0

The fix will be delivered in version 1.7

Original comment by aso...@gmail.com on 25 Apr 2010 at 7:01