[Bug]: `ScriptUtils` converts adjacent string literals to invalid syntax

Open
#11,206 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@marktech0813 is already working on this.

Since Nov 11, 2025.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
java, postgresql

Research direction

Start in ScriptUtils.java around executeDatabaseScript, using the PostgreSQL script shown in the report to reproduce the statement splitting. Verify the resulting statements preserve the required separation between adjacent string literals and that the script executes successfully against PostgreSQL.

Written by the indexing model from the issue text.

Description

type/bug
Module

PostgreSQL

Testcontainers version

2.0.1

Using the latest Testcontainers version?

Yes

Host OS

macOS

Host Arch

arm64

Docker version
Client:
 Version:           28.5.1
 API version:       1.51
 Go version:        go1.24.8
 Git commit:        e180ab8
 Built:             Wed Oct  8 12:16:17 2025
 OS/Arch:           darwin/arm64
 Context:           desktop-linux

Server: Docker Desktop 4.49.0 (208700)
 Engine:
  Version:          28.5.1
  API version:      1.51 (minimum version 1.24)
  Go version:       go1.24.8
  Git commit:       f8215cc
  Built:            Wed Oct  8 12:18:25 2025
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.7.27
  GitCommit:        05044ec0a9a75232cad458027ca83437aae3f4da
 runc:
  Version:          1.2.5
  GitCommit:        v1.2.5-0-g59923ef
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
What happened?

ScriptUtils splits an init script into a list of statements. This is valid syntax:

CREATE TABLE test (
    x int
);

COMMENT ON COLUMN test.x
    IS 'First sentence. '
    'Second sentence';

But ScriptUtils converts this into these two statements:

CREATE TABLE test ( x int )
COMMENT ON COLUMN test.x IS 'First sentence. ' 'Second sentence'

The second statement isn't valid because the adjacent string literals need to be separated by at least one newline.

Relevant log output
Caused by: org.testcontainers.ext.ScriptUtils$ScriptStatementFailedException: Script execution failed (initPostgres.sql:2): COMMENT ON COLUMN test.x IS 'First sentence. ' 'Second sentence'
	at org.testcontainers.jdbc.JdbcDatabaseDelegate.execute(JdbcDatabaseDelegate.java:63)
	at org.testcontainers.delegate.AbstractDatabaseDelegate.execute(AbstractDatabaseDelegate.java:38)
	at org.testcontainers.ext.ScriptUtils.executeDatabaseScript(ScriptUtils.java:307)
	... 83 common frames omitted
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "'Second sentence'"
  Position: 48
	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2736)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2421)
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:372)
	at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:525)
	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:435)
	at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:357)
	at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:342)
	at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:318)
	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:313)
	at org.testcontainers.jdbc.JdbcDatabaseDelegate.execute(JdbcDatabaseDelegate.java:50)
	... 85 common frames omitted
Additional Information

No response

Dominant language
Java
Stars
8.8k
Forks
2k
Avg merge
2d 1h
Merged PRs (30d)
11

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from testcontainers/testcontainers-java

All issues in testcontainers/testcontainers-java

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.