testcontainers / testcontainers/testcontainers-java
[Bug]: Underlying NullPointerException in ContainerLessJdbcDelegate when using ScriptUtils
まだ誰も着手していません。
- 主要言語
- Java
- スター
- 8.7k
- フォーク
- 1.9k
- 平均マージ
- 2日 17時間
- マージ済み PR(30日)
- 9
説明
Module
Core
Testcontainers version
1.21.4
Using the latest Testcontainers version?
Yes
Host OS
Windows
Host Arch
x64
Docker version
Client:
Version: 29.0.2-rd
API version: 1.51 (downgraded from 1.52)
Go version: go1.25.4
Git commit: 5a2d7eb
Built: Tue Nov 18 23:34:16 2025
OS/Arch: windows/amd64
Context: default
Server:
Engine:
Version: 28.3.3
API version: 1.51 (minimum version 1.24)
Go version: go1.24.8
Git commit: bea959c7b793b32a893820b97c4eadc7c87fabb0
Built: Sun Oct 12 08:01:14 2025
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v2.1.5
GitCommit: fcd43222d6b07379a4be9786bda52438f0dd16a1
runc:
Version: 1.3.3
GitCommit: d842d7719497cc3b774fd71620278ac9e17710e0
docker-init:
Version: 0.19.0
GitCommit:
What happened?
Hi,
When running a script with ScriptUtils on ContainerLessJdbcDelegate an underlying NullPointerException occurs.
ScriptUtils.runInitScript( new ContainerLessJdbcDelegate( connection ), initScript );
Reason is the code in org.testcontainers.jdbc.JdbcDatabaseDelegate#closeConnectionQuietly. It closes the connection which is null, as the ContainerLessJdbcDelegate has an own connection field. This could probably be solved by implementing closeConnectionQuietly in ContainerLessJdbcDelegate and closing the own field instead of the one on the super class.
Thank you and best regards
Nils
Relevant log output
2026-03-12 08:28:11 ERROR [main ] o.t.j.JdbcDatabaseDelegate - Could not close JDBC connection
java.lang.NullPointerException: Cannot invoke "java.sql.Connection.close()" because "this.connection" is null
at org.testcontainers.jdbc.JdbcDatabaseDelegate.closeConnectionQuietly(JdbcDatabaseDelegate.java:72)
at org.testcontainers.jdbc.JdbcDatabaseDelegate.closeConnectionQuietly(JdbcDatabaseDelegate.java:16)
at org.testcontainers.delegate.AbstractDatabaseDelegate.close(AbstractDatabaseDelegate.java:45)
at org.testcontainers.ext.ScriptUtils.executeDatabaseScript(ScriptUtils.java:308)
at org.testcontainers.ext.ScriptUtils.executeDatabaseScript(ScriptUtils.java:225)
at org.testcontainers.ext.ScriptUtils.runInitScript(ScriptUtils.java:213)
Additional Information
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
org.testcontainers.jdbc.JdbcDatabaseDelegate#closeConnectionQuietly から始めて、ContainerLessJdbcDelegate の connection フィールドを調べ、その後、レポートに示されている ScriptUtils.runInitScript の呼び出しを追跡します。ContainerLessJdbcDelegate を使ってスクリプトを実行する回帰テストを追加し、正しい接続を閉じながら NullPointerException なしで完了することを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- java
- 領域
- database, testing
- issue の種類
- バグ
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 52/100