javac exits with error "constant string too long" (Doc ID 1328852.1)

Last updated on NOVEMBER 05, 2016

Applies to:

Java SE JDK and JRE - Version 5.0 to 8
Information in this document applies to any platform.

Symptoms

The Java language compiler 'javac' fails to compile Java source code
and exits with error message "constant string too long". Example:

$ javac BigString.java
BigString.java:2: constant string too long
    String myConst=""+
                     ^
1 error

Changes

You have created new source code or changed existing source code. Example:

public class BigString {
    String myConst = ""+
    "... /* the length of this String is greater or equal than 0xFFFF chars */ ...";
}


For an actual example see BigString.java

Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms