Home > Net >  java: unclosed character literal while running test in IntelliJ
java: unclosed character literal while running test in IntelliJ

Time:02-16

I'm having trouble launching single unit tests from IntelliJ IDEA IDE because of the error:

 java: unclosed character literal

which is found in many places of my working codebase. This error prevents the IDE to compile the codebase and launch the tests.

Instead, when I launch the tests with maven I get no error at all. The points that give me error are single chars usage like these:

stringVal.append(date).append('§');

or

translateLabel(s.replace('«','<'))

So the error is improper, considering that I am not using single quotes to declare strings.

I guess it has something to do with the encoding, so the IntelliJ Idea IDE is like seeing more than 1 char among those quotes, but maven interprets them correctly and returns no error at all.

I've tried to adjust the IDE configuration to bring to warnings the encoding errors but with no result.

Any suggestion?

CodePudding user response:

This is most probably an encoding problem: the source code is probably encoded using UTF-8 which means that § is stored as two bytes.

If the IDE tries to read these two bytes using the ISO-LATIN-1 charset this gives the characters § (i.e. two characters).

To tell IntelliJ to use UTF-8 for your project go to the settings, search for "project encoding" and change it to UTF-8.

  • Related