testcontainers/testcontainers-java · error · java.lang.UnsupportedOperationException
Provide implementation in subclass
Error message
Provide implementation in subclass
What it means
Transferable's default updateChecksum(Checksum) throws UnsupportedOperationException('Provide implementation in subclass') because checksumming is only meaningful for Transferables that actually carry content. Calling it on a base/default implementation (e.g. an empty Transferable or a custom one that didn't override it) hits this stub.
Solutions
- Override updateChecksum(Checksum) in your Transferable subclass and feed it the content bytes
- If your Transferable has no content, override it as a no-op instead of relying on the default
- Extend from MountableFile or an existing implementation that already implements checksums
- Check for a library upgrade where your Transferable type implements updateChecksum
Example fix
// before
class MyFile implements Transferable { /* no updateChecksum */ }
// after
class MyFile implements Transferable {
@Override
public void updateChecksum(Checksum checksum) {
checksum.update(getBytes(), 0, getBytes().length);
}
} Defensive patterns
Strategy: type-guard
Validate before calling
// check the implementation actually supports checksumming
static boolean supportsChecksum(Transferable t) {
try { t.updateChecksum(new java.util.zip.CRC32()); return true; }
catch (UnsupportedOperationException e) { return false; }
} Type guard
// narrow to implementations known to override updateChecksum
if (transferable instanceof MountableFile) {
((MountableFile) transferable).updateChecksum(checksum);
} Try / catch
try {
transferable.updateChecksum(checksum);
} catch (UnsupportedOperationException e) {
// fall back to identity/skip checksum for contentless transferables
logger.warn("Transferable {} does not support checksums", transferable.getDescription());
} Prevention
- When implementing Transferable, always override updateChecksum and getBytes
- Use abstract base classes that force the override instead of raw interface implementation
- Add a unit test that checksums every custom Transferable you ship
- Prefer extending MountableFile over implementing Transferable from scratch
When it happens
Trigger: Invoking updateChecksum() on a Transferable that does not override it — e.g. a custom Transferable implementation missing the override, or framework code computing a checksum over a contentless default Transferable.
Common situations: Writing a custom Transferable for ImageFromDockerfile and forgetting to override updateChecksum; new framework code path that checksums all Transferables including defaults.
Understand the failure class
Background: "NotImplementedError: Subclasses should override this method" / "must be implemented" — abstract method errors explained — this error's family across 40 libraries.
Related errors
- getTestHostIpAddress() is only implemented for…
- The ClickHouse does not support this
- Setting a in not supported in the versions below 22.1.0
- getParentLogger not supported
- The Oracle Database driver does not support this
AI-assisted analysis of testcontainers/testcontainers-java@8e549514e3 (2026-09-12).
Data as JSON: /api/errors/e21db39b9c720101.
Report an issue: GitHub.
Appendix: source
Thrown at core/src/main/java/org/testcontainers/images/builder/Transferable.java:98
try {
tarArchiveOutputStream.putArchiveEntry(tarEntry);
IOUtils.write(getBytes(), tarArchiveOutputStream);
tarArchiveOutputStream.closeArchiveEntry();
} catch (IOException e) {
throw new RuntimeException("Can't transfer " + getDescription(), e);
}
}
default byte[] getBytes() {
return new byte[0];
}
default String getDescription() {
return "";
}
default void updateChecksum(Checksum checksum) {
throw new UnsupportedOperationException("Provide implementation in subclass");
}
}
View on GitHub (pinned to 8e549514e3)