7

I have a Java project and I'm using Apache Maven. All this time I was using Maven Java compiler plugin with parameters source=1.5 and target=1.5 defined in pom.xml file. Since I changed it to source=1.6 and target=1.6 I'm getting the following error:

XXXXXXXX.java:[54,27] unmappable character for encoding UTF-8

I've been testing different configurations and I turned showWarnings to value true so I could see that with value 1.5 for source and target this is a warning and not an error.

I need to change the Java compiler configuration anyway. Does anybody know why is this so and how can I solve this problem without editing all Java source files (there are hundreds of files with this issue now)?

2
  • Have you looked at what is at line 54 column 27 of file XXXXXXXX.java to see what is there? Try it with a hex capable editor as well, or something that can show hidden characters like notepad++
    – Dave G
    Aug 26, 2011 at 9:42
  • 1
    It's an encoding problem with an special latin character in a paragraph (all errors are in code comments). If I try with encoding=ISO-8859-1 it compiles OK (I cannot change the whole project character encoding anyhow). My question is: why is this an error with source=1.6 and target=1.6 and it's a warning with source=1.5 and target=1.5?
    – joragupra
    Aug 26, 2011 at 10:05

1 Answer 1

12

My question is: why is this an error with source=1.6 and target=1.6 and it's a warning with source=1.5 and target=1.5?

Short anwser, because they said so:

-source 1.6 This is the default value. No language changes were introduced in Java SE 6. However, encoding errors in source files are now reported as errors, instead of warnings, as previously.

@DaveG concerns are valid, and you should try to:

  • Change the file encoding of your source files
  • find/replace those chars with your IDE
4
  • Good catch. Java has historically been really lax about encoding errors. I have been trying to get folks to use it in a way that reports encoding errors as errors, but you have to work at it. It's good that these are now caught.
    – tchrist
    Aug 26, 2011 at 12:08
  • Absolutely. This will save hours of tedious debugging and "my webapp shows weird chars" questions on SO! Aug 26, 2011 at 12:10
  • @Brian awesome catch on that. Hadn't considered chasing it down through the documentation
    – Dave G
    Aug 26, 2011 at 12:39
  • 2
    Why this throw error even in comments? It realy not so funny.
    – msangel
    Nov 4, 2013 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.