testcontainers / testcontainers/testcontainers-java
[Bug]: HiveMQExtension / Class Loading Issue
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 8.7k
- Forks
- 1.9k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 9
Description
Module
HiveMQ
Testcontainers version
1.20.6
Using the latest Testcontainers version?
Yes
Host OS
Linux
Host Arch
x64
Docker version
27.4
What happened?
Hello,
if you want to proplery JUnit Test a HiveMQExtension you need to unfortunately add all depencies used via the method "addAdditionalClass". However the following code leads to an exception "Unclosed character class near index 6
/[B$.*" due to following code:
private void putSubclassesIntoJar(
final @NotNull String extensionId,
final @Nullable Class<?> clazz,
final @NotNull JavaArchive javaArchive
) throws NotFoundException {
if (clazz != null) {
final Set<String> subClassNames = ClassPool
.getDefault()
.get(clazz.getName())
.getClassFile()
.getConstPool()
.getClassNames();
for (final String subClassName : subClassNames) {
final String className = subClassName.replaceAll("/", ".");
if (!className.startsWith("[L")) {
LOGGER.debug("Trying to package subclass '{}' into extension '{}'.", className, extensionId);
javaArchive.addClass(className);
} else {
LOGGER.debug("Class '{}' will be ignored.", className);
}
}
}
}
Based on inpuit "subClassNames" can include "[B" in additition to "[L" (already checked). I would propose to add another case OR allow the proplery extend this class in general (unfortunately private constructor) ...
Relevant log output
Additional Information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the putSubclassesIntoJar method shown in the report and inspect how ClassPool class names are converted before JavaArchive.addClass is called. Reproduce the HiveMQExtension setup with addAdditionalClass and a [B entry, then verify that class loading completes without the reported exception and that the existing [L handling remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100