testcontainers / testcontainers/testcontainers-java

[Bug]: HiveMQExtension / Class Loading Issue

Open
#10,074 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

modules/hivemq type/bug
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

Open the contributing guide

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.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.