Java version compatibility issues causing compilation errors in a Spring Boot application

thevagabond
Fri, 06 Dec 2024 20:29:50 +0000
Troubleshooting and help

I’m encountering compilation errors in my Spring Boot application, which seem to be related to Java version incompatibility. Initially, I had issues with a multi-line string literal, which I resolved by converting it to a single line. However, now I’m facing a new error related to the Spring Boot class file version.

As per my pom.xml :

<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>3.3.5</version>
<relativePath/>
	</parent>

<java.version>17</java.version>

First my program had following line :

String createTriggerSQL = """
                CREATE TRIGGER prevent_excess_books
                BEFORE INSERT ON book_ownership
                FOR EACH ROW
                BEGIN
                    DECLARE book_count INT;
                    SELECT COUNT(*) INTO book_count
                    FROM book_ownership
                    WHERE id = NEW.id;
                    IF book_count >= 10 THEN
                        SIGNAL SQLSTATE '45000'
                        SET MESSAGE_TEXT = 'User cannot own more than 10 books.';
                    END IF;
                END;
                """;

for which the error pointed out semi-colon ‘;’ :

[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /workspace/src/main/java/edu/unc/cs/BookSwap/DatabaseInitializer/DatabaseInitializer.java:[25,37] unclosed string literal
[ERROR] /workspace/src/main/java/edu/unc/cs/BookSwap/DatabaseInitializer/DatabaseInitializer.java:[26,31] ‘;’ expected
[ERROR] /workspace/src/main/java/edu/unc/cs/BookSwap/DatabaseInitializer/DatabaseInitializer.java:[27,23] ‘;’ expected
[ERROR] /workspace/src/main/java/edu/unc/cs/BookSwap/DatabaseInitializer/DatabaseInitializer.java:[27,33] ‘;’ expected
[ERROR] /workspace/src/main/java/edu/unc/cs/BookSwap/DatabaseInitializer/DatabaseInitializer.java:[28,20] ‘;’ expected
[ERROR] /workspace/src/main/java/edu/unc/cs/BookSwap/DatabaseInitializer/DatabaseInitializer.java:[28,29] ‘;’ expected
[ERROR] /workspace/src/main/java/edu/unc/cs/BookSwap/DatabaseInitializer/DatabaseInitializer.java:[30,28] ‘;’ expected
[ERROR] /workspace/src/main/java/edu/unc/cs/BookSwap/DatabaseInitializer/DatabaseInitializer.java:[31,33] ‘;’ expected
[ERROR] /workspace/src/main/java/edu/unc/cs/BookSwap/DatabaseInitializer/DatabaseInitializer.java:[31,52] ‘;’ expected
[ERROR] /workspace/src/main/java/edu/unc/cs/BookSwap/DatabaseInitializer/DatabaseInitializer.java:[32,40] ‘;’ expected
[ERROR] /workspace/src/main/java/edu/unc/cs/BookSwap/DatabaseInitializer/DatabaseInitializer.java:[34,34] ‘;’ expected
[ERROR] /workspace/src/main/java/edu/unc/cs/BookSwap/DatabaseInitializer/DatabaseInitializer.java:[35,31] ‘;’ expected
[ERROR] /workspace/src/main/java/edu/unc/cs/BookSwap/DatabaseInitializer/DatabaseInitializer.java:[35,41] unclosed character literal
[ERROR] /workspace/src/main/java/edu/unc/cs/BookSwap/DatabaseInitializer/DatabaseInitializer.java:[35,32] not a statement
[ERROR] /workspace/src/main/java/edu/unc/cs/BookSwap/DatabaseInitializer/DatabaseInitializer.java:[35,47] illegal line end in character literal
[ERROR] /workspace/src/main/java/edu/unc/cs/BookSwap/DatabaseInitializer/DatabaseInitializer.java:[36,44] unclosed character literal
[ERROR] /workspace/src/main/java/edu/unc/cs/BookSwap/DatabaseInitializer/DatabaseInitializer.java:[36,56] ‘;’ expected
[ERROR] /workspace/src/main/java/edu/unc/cs/BookSwap/DatabaseInitializer/DatabaseInitializer.java:[36,65] ‘;’ expected
[ERROR] /workspace/src/main/java/edu/unc/cs/BookSwap/DatabaseInitializer/DatabaseInitializer.java:[36,66] not a statement
[ERROR] /workspace/src/main/java/edu/unc/cs/BookSwap/DatabaseInitializer/DatabaseInitializer.java:[36,70] ‘;’ expected
[ERROR] /workspace/src/main/java/edu/unc/cs/BookSwap/DatabaseInitializer/DatabaseInitializer.java:[36,80] unclosed character literal
[ERROR] /workspace/src/main/java/edu/unc/cs/BookSwap/DatabaseInitializer/DatabaseInitializer.java:[36,79] not a statement
[ERROR] /workspace/src/main/java/edu/unc/cs/BookSwap/DatabaseInitializer/DatabaseInitializer.java:[38,17] not a statement
[ERROR] /workspace/src/main/java/edu/unc/cs/BookSwap/DatabaseInitializer/DatabaseInitializer.java:[39,19] unclosed string literal
[ERROR] /workspace/src/main/java/edu/unc/cs/BookSwap/DatabaseInitializer/DatabaseInitializer.java:[39,17] not a statement
[INFO] 25 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

Then I made the statement one line :
String createTriggerSQL = "CREATE TRIGGER prevent_excess_books BEFORE INSERT ON book_ownership FOR EACH ROW BEGIN DECLARE book_count INT; SELECT COUNT(*) INTO book_count FROM book_ownership WHERE id = NEW.id; IF book_count >= 10 THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'User cannot own more than 10 books.'; END IF; END;";

Now my error log shows :

[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-manager/2.15.0/plexus-compiler-manager-2.15.0.jar (5.2 kB at 476 kB/s)
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/com/thoughtworks/qdox/qdox/2.0.3/qdox-2.0.3.jar (334 kB at 22 MB/s)
[INFO] Recompiling the module because of changed dependency.
[INFO] Compiling 33 source files with javac [debug parameters release 17] to target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /workspace/src/main/java/edu/unc/cs/BookSwap/BookSwapApplication.java:[3,32] cannot access org.springframework.boot.SpringApplication
bad class file: /layers/heroku_maven/repository/org/springframework/boot/spring-boot/3.3.5/spring-boot-3.3.5.jar(org/springframework/boot/SpringApplication.class)
class file has wrong version 61.0, should be 52.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

IN second case, it is interseting to note “heroku_maven” (i never created this repo in my app anywhere) in

[3,32] cannot access org.springframework.boot.SpringApplication
bad class file: /layers/heroku_maven/repository/org/springframework/boot/spring-boot/3.3.5/spring-boot-3.3.5.jar(org/springframework/boot/SpringApplication.class)

3 posts - 2 participants