On Thu, 22 Feb 2024 at 12:08, Andrew Coates <big.andy.coa...@gmail.com>
wrote:

> Hi all,
>
> I'm seeing a runtime failure using TarArchiveOutputStream when updating to
> commons-compress 1.26.0.
>
> java.lang.NoClassDefFoundError: org/apache/commons/codec/Charsets
>         at org.apache.commons.compress@1.26.0
>
> /org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.<init>(TarArchiveOutputStream.java:212)
>         at org.apache.commons.compress@1.26.0
>
> /org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.<init>(TarArchiveOutputStream.java:157)
>         at org.apache.commons.compress@1.26.0
>
> /org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.<init>(TarArchiveOutputStream.java:147)
>         at testcontainers@1.19.5
>
> /org.testcontainers.containers.ContainerState.copyFileToContainer(ContainerState.java:350)
>         ...
>
> Commons-compress 1.26.0 contains changes to make use of commons-codec,
> rather than its own copy of files, but I see that the POM marks
> commons-codec as *optional*. Excuse my potential ignorance, but I thought
> optional dependencies shouldn't cause runtime failures if not present.  Is
> this not the case?


No that’s not the case here or in the maven/java eco system in general.

It is possible to have that behaviour within a Java app/lib but the app/lib
would have to explicitly have code which detected the presence/absence of a
dependency to not fail and have an alternative mechanism for the
functionality.

For the vast majority of Java apps/libs that have an optional dependency it
means that the dependency is only required for a subset of the
functionality and if you don’t use that subset then it’s not required, but
if you do use that subset then you have to explicitly add that dependency.

Obviously, I can just add commons-codec as an explicit dependency. But this
> seems wrong IMHO.


That is the correct thing to do.

Should I sign up for an account and raise this as a bug in Jira?
>

It would be good to have documented which features require commons codec
and I don't see anything on the Compress site/user guide which indicates
this, so I think it would be worth raising a ticket to improve the docs for
this.

I'm not that familiar with compress, but it looks like LZ4
(FramedLZ4CompressorInputStream & FramedLZ4CompressorOutputStream),
snappy-framed (FramedSnappyCompressorInputStream &
FramedSnappyCompressorOutputStream) and the CompressorStreamFactory require
the Codec dependency

Niall

Thanks,
>
> Andy
>

Reply via email to