Skip to content

Conversation

@sagarkhandagre998
Copy link

@sagarkhandagre998 sagarkhandagre998 commented Dec 11, 2025

Problem - When running tests with -DuseInMemoryDatabase=false, many tests fail with NullPointerException at line 341 in getRuntimeProperties().

Error Pattern:
[ERROR] DrugOrderValidatorTest.:53->BaseContextSensitiveTest.:208 >BaseContextSensitiveTest.getRuntimeProperties:341 » NullPointer

Root Cause
In both BaseContextSensitiveTest classes (JUnit 4 and JUnit 5), but this error comes from Junit 5 when useInMemoryDatabase=false: The code reads system properties (databaseUrl, databaseUsername, databasePassword, databaseDriver, databaseDialect) that may be null. These null values are passed directly to runtimeProperties.setProperty(). Later access to these properties causes NullPointerException.

The issue occurs because:
Containers.ensureDatabaseRunning() may not have set the system properties yet, or The properties weren't set manually, or There was a failure in the container initialization.

Solution

  1. Added validation in both test base classes: Null check for runtimeProperties: ensure it's not null after loading from TestUtil.getRuntimeProperties().
  2. Validation of system properties: check all required database properties before use.
  3. Clear error handling: throw IllegalStateException with a helpful message instead of NPE.

Suggested Entire Fix

  1. The NPE is resolved by validation, but the root cause remains: missing system properties (databaseUrl, databaseUsername, databasePassword, databaseDriver, databaseDialect) when useInMemoryDatabase=false.

  2. To fully fix the error, we must ensure those properties are set before tests start—either by letting Containers.ensureDatabaseRunning() set them, or by passing them explicitly on the Maven command line.

  3. If using MySQL, swap the driver/dialect and URL accordingly.

  4. If Containers.ensureDatabaseRunning() is supposed to set these automatically, we should verify why it isn’t running or isn’t able to set them in the current environment (e.g., missing -Ddatabase flag, Testcontainers disabled, or network/permission issues).

… junit5 - BaseContextSensitiveTest.java and Added validation for system properties in the else block. (Fix NPE for Integration Test Failures running on mysql or postgresql).
…or Integration Test Failures running on mysql or postgresql)
@sagarkhandagre998
Copy link
Author

Need Clarification - We have find the breaking point and tackled that by adding validation but the main error is from System properties. We need to check why the database is not running or isn’t able to set the database props in the current environment (Containers.java) .

@dkayiwa
Copy link
Member

dkayiwa commented Dec 11, 2025

We need to check why the database is not running or isn’t able to set the database props in the current environment (Containers.java) .

Can you investigate that too?

@sagarkhandagre998
Copy link
Author

Sure I will do that.

@sagarkhandagre998
Copy link
Author

sagarkhandagre998 commented Dec 12, 2025

We need to check why the database is not running or isn’t able to set the database props in the current environment (Containers.java) .

Can you investigate that too?

The actual error is comming from Containers.java where test container is not able to connect with docker, if the docker is not started or running so thats why it was not able to set the system props results in NPE but we have implements the validation for NPE and now i have also implmented the validation checks for Containers.java to handle the connection with docker. After starting the docker locally the test container is succesfully connected with docker.

… docker that handles Docker connection failure.
@sagarkhandagre998
Copy link
Author

@dkayiwa Improved Exceptional handling in Containers.java to get the actual error while running the test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants