Skip to content

Conversation

@arturobernalg
Copy link
Member

Refactor codec integration to load Commons Compress via reflection. This removes compile-time references, respects the optional dependency, and eliminates ExceptionInInitializerError when the library is missing. runtimeAvailable() now probes Commons Compress algorithm classes

@arturobernalg arturobernalg requested a review from ok2c October 12, 2025 09:38
@ok2c
Copy link
Member

ok2c commented Oct 12, 2025

@arturobernalg Why is CommonsCompressingEntity using reflection? I do not think it should be. So should not be CommonsCompressDecoderFactory. The only class making use of reflection should CommonsCompressSupport if everything has been properly designed.

@ok2c
Copy link
Member

ok2c commented Oct 12, 2025

@arturobernalg Please sort out the problem with multiple "brotli" dependencies.

@ok2c
Copy link
Member

ok2c commented Oct 12, 2025

@arturobernalg OK. As a first step please do the following. Make CommonsCompressingEntity work the same way as DecompressingEntity and take IOFunction<OutputStream, OutputStream> encoder as an injectable dependency. Extract reflective code from CompressingEntity to CommonsCompressDecoderFactory. Rename CommonsCompressingEntity to CompressingEntity. Rename CommonsCompressDecoderFactory to CommonsCompressCodecFactory.

@arturobernalg
Copy link
Member Author

@arturobernalg OK. As a first step please do the following. Make CommonsCompressingEntity work the same way as DecompressingEntity and take IOFunction<OutputStream, OutputStream> encoder as an injectable dependency. Extract reflective code from CompressingEntity to CommonsCompressDecoderFactory. Rename CommonsCompressingEntity to CompressingEntity. Rename CommonsCompressDecoderFactory to CommonsCompressCodecFactory.

@ok2c I just Replaced Commons Compress with brotli4j for both encode and decode in the async round-trip example. Please let me now if is what you was thinking

@ok2c
Copy link
Member

ok2c commented Oct 12, 2025

@arturobernalg This is much, much better in my opinion .I just do not like that two distinct changes got mixed up in a single change-set. Would it be a big deal for you to spin Brotli related changes into a separate pull request?

Some javadocs (CompressingEntity for instance) also are no longer in sync with the code. This should be revised.

@arturobernalg arturobernalg force-pushed the cc-reflective-codecs branch 2 times, most recently from a638555 to 15290d1 Compare October 12, 2025 17:10
@arturobernalg
Copy link
Member Author

@arturobernalg This is much, much better in my opinion .I just do not like that two distinct changes got mixed up in a single change-set. Would it be a big deal for you to spin Brotli related changes into a separate pull request?

Some javadocs (CompressingEntity for instance) also are no longer in sync with the code. This should be revised.

@fixed. I'm separating the PR in two. Another one is coming with the only reflection on Brotli

Copy link
Member

@ok2c ok2c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arturobernalg Looks good otherwise.

m.put(ContentCoding.GZIP,
new Codec(
// encoder
org.apache.hc.client5.http.entity.GzipCompressingEntity::new,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arturobernalg There is no need to use a fully qualified class name. It can be imported

ent -> new DecompressingEntity(ent, GZIPInputStream::new)));
m.put(ContentCoding.DEFLATE,
new Codec(
org.apache.hc.client5.http.entity.DeflateCompressingEntity::new,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prevent EIIE when commons-compress is absent; wrap failures as IOException.
Fix runtimeAvailable() to probe CC classes; decouple from helper JARs.
@arturobernalg arturobernalg merged commit cf54f60 into apache:master Oct 13, 2025
10 checks passed
Comment on lines -80 to -84
<dependency>
<groupId>org.brotli</groupId>
<artifactId>dec</artifactId>
<optional>true</optional>
</dependency>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused. Why has this dependency declaration been removed? There are still (reflective) usages of these classes in the library:

httpclient5/src/main/java/org/apache/hc/client5/http/entity/BrotliDecompressingEntity.java
52:            Class.forName("org.brotli.dec.BrotliInputStream");

httpclient5/src/main/java/org/apache/hc/client5/http/entity/compress/CommonsCompressCodecFactory.java
76:    private static final String H_BROTLI = "org.brotli.dec.BrotliInputStream";

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please @rschmitt take a look to this PR 738 where everything is tackle

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rschmitt I asked @arturobernalg to move brotli related changes to a separate change-set. This must have contributed to the confusion.

Copy link
Member

@ok2c ok2c Oct 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arturobernalg @rschmitt I would like to revert some of reflective calls in CommonsCompressCodecFactory. They are unnecessary if ContentCodecRegistry works correctly and does not call any of CommonsCompressCodecFactory methods at runtime if Commons Compress is not present.

ok2c pushed a commit that referenced this pull request Oct 14, 2025
ok2c pushed a commit that referenced this pull request Oct 14, 2025
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.

3 participants