#376 Various encoding problems when parsing XML

release_4.0
closed
Oliver Burn
5
2012-10-10
2005-10-09
No

Checkstyle parses various XML files using a FileReader.
Since the FileReader uses the platform encoding and not
the encoding from the actual XML file it might distort the
content of the file or make the file even unparsable.

Please read here for more detailed info about this
problem:
http://weblogs.java.net/blog/javaben/archive/2005/09/
xml_readers_and.html

This means all occurances of FileReader (when parsing
XML) should be extinct and FileInputStream used
instead.
This way the parser will honor the actual encoding from
the XML file.

Problematic occurrances are:
PackageNamesLoader
ImportControlLoader
SupressionsLoader

To prove that this is not just an theoretical problem I
append the mail I got from a fellow plugin developer:

Hi Lars!

I am trying the new custom check support functionnality
(as you described it on the web site).
I followed your guide. Everything got fine untill I tried to
actually run the check when building a project: I get an
error telling me: "The 'checkstyle_packages.xml' file is
declared to be UTF-8 whereas it is Cp1252". But the
"checkstyle_packages.xml" I modified is really UTF-8!
Then I changed the encoding of this very file from UTF-8
to Cp1252, and this works now. So I guess that's a little
bug with the parser that should use UTF-8 instead of the
platform dependent encoding (Cp1252 in this very case).

Oh, also: the custom checks I used are i18ned, but the
plugin does not show i18n messages (only the keys).
Maybe there's a little problem with the classloader...

Apart from that, this is cool to be able to add quite easily
custom checks :o)

Hope everything's fine for you!
Cheers,
Fabrice.

Discussion

  • Oliver Burn
    Oliver Burn
    2005-10-10

    Logged In: YES
    user_id=218824

    Thanks for filing this - I will make the change.

     
  • Oliver Burn
    Oliver Burn
    2005-10-19

    Logged In: YES
    user_id=218824

    Fixed in CVS. Will be part of next build.