Cosmic-IDE icon indicating copy to clipboard operation
Cosmic-IDE copied to clipboard

Java String concatenation gives Fatal Error: Unable to find method makeConcatWithConstants

Open john-black-3k opened this issue 8 months ago • 0 comments

I have the following Java code:

package com.nbsp.cosmicide.example2;

public final class Main {
	public static void main(String[] args) {
		System.out.println("Hello, World!");
		
		int i = 3;
		String s1 = String.valueOf(i);
		System.out.println("s1 = " + s1);
	}
}

Compiling this gives the following error:

INFO: Compiling Kotlin code
INFO: No Kotlin files are present. Skipping Kotlin compilation.
INFO: Successfully run KotlinCompiler.
INFO: Compiling Java code
INFO: Compilingg
INFO: Compiling 1 java file...
INFO: Fatal Error: Unable to find method makeConcatWithConstants
INFO: Fatal Error: Unable to find method makeConcatWithConstants

INFO: Fatal Error: Unable to find method makeConcatWithConstants

ERROR: /storage/emulated/0/Android/data/org.cosmicide/files/projects/Example2/src/main/java/com/nbsp/cosmicide/example2/Main.java:9: cannot find symbol
  symbol:   method makeConcatWithConstants(java.lang.invoke.MethodHandles.Lookup,java.lang.String,java.lang.invoke.MethodType,java.lang.String)
  location: interface java.lang.invoke.StringConcatFactory
OUTPUT: Failed to compile JavaCompileTask code.
INFO: Successfully run JavaCompileTask.

This seems to be related to how String concatenation is performed in Java 9+. The error does not appear if adding the following Javac flag: -XDstringConcat=inline.

Please see the following:

  • https://stackoverflow.com/questions/58681265/how-to-turn-off-string-concatenation-optimization
  • https://stackoverflow.com/questions/46512888/how-is-string-concatenation-implemented-in-java-9

john-black-3k avatar Jun 15 '24 18:06 john-black-3k