Skip to content

Inline only needed format-avro helper classes in OSGi bundle - #1649

Draft
bhardwaj-priyanshu wants to merge 1 commit into
developfrom
fix/strip-format-avro-nested-jars
Draft

bhardwaj-priyanshu wants to merge 1 commit into
developfrom
fix/strip-format-avro-nested-jars

Conversation

@bhardwaj-priyanshu

Copy link
Copy Markdown
Contributor

Summary

Updates maven-bundle-plugin <Embed-Dependency> in pom.xml to inline only the non-@Plugin Avro helper classes used by BigQuery, Pub/Sub, and Dataplex (AvroToStructuredTransformer*.class, StructuredToAvroTransformer*.class, input/CombineAvroInputFormat*.class, input/PathTrackingAvroInputFormat*.class) and exclude format-avro from lib/ (!format-avro), while keeping all transitive compile dependencies in lib/.

Why

format-avro is packaged as an OSGi plugin bundle whose own lib/*.jar entries cannot be loaded by CDAP's depth-1 plugin unpacker when embedded inside google-cloud-*.jar!/lib/. Inlining only the 6 referenced helper .class files (including inner classes) removes 11.3 MB of unreachable nested JARs while keeping runtime classloading identical.

Verification

  • Bundle size drops from 202,986,948 bytes to 191,652,063 bytes (-11,334,885 bytes).
  • lib/ removes only lib/format-avro-2.13.0.jar (155 -> 154 JARs); all 154 remaining lib/*.jar entries have identical SHA-256 hashes.
  • Export-Package (498 clauses) and @Plugin class set (29 plugins) are 100% identical.
  • All 6 inlined .class files have identical bytecode SHA-256 to format-avro-2.13.0.jar, constant-pool scan confirms zero dangling references, and live JDK 11 depth-1 URLClassLoader ABI check confirms identical method/constructor signatures.
  • 164/164 targeted unit tests (BigQueryAvroConverterTest, PubSub*Test, Dataplex*Test, TestDelegatingGCSOutputCommitter) pass.

format-avro is an OSGi plugin bundle containing nested lib/*.jar files.
Embedding format-avro as a whole JAR under google-cloud.jar!/lib/ adds
11.3 MB of dead nested JARs that CDAP's depth-1 PluginClassLoader unpacker
never places on the classpath.

Update maven-bundle-plugin Embed-Dependency to inline only the 4 non-@plugin
Avro helper class families used by BigQuery, Pub/Sub, and Dataplex
(AvroToStructuredTransformer, StructuredToAvroTransformer,
CombineAvroInputFormat, PathTrackingAvroInputFormat) and exclude format-avro
from lib/ while keeping all transitive compile dependencies embedded.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request modifies the pom.xml to inline only specific non-@plugin Avro helper classes from format-avro instead of embedding all dependencies, which prevents dead nested JARs from being included in google-cloud.jar. The reviewer points out that hardcoding these specific class patterns introduces a tight coupling with format-avro internals, creating a risk of silent runtime errors (such as NoClassDefFoundError) if the dependency is upgraded and refactored. To mitigate this, the reviewer suggests expanding the XML comment to explicitly warn future developers about this fragility.

Comment thread pom.xml
Comment on lines +1012 to +1017
<!--
Inline only the non-@Plugin Avro helper classes used by BigQuery,
Pub/Sub, and Dataplex so format-avro's dead nested lib/*.jar
entries are not embedded inside google-cloud.jar!/lib/.
-->
<Embed-Dependency>format-avro;inline=io/cdap/plugin/format/avro/AvroToStructuredTransformer*.class|io/cdap/plugin/format/avro/StructuredToAvroTransformer*.class|io/cdap/plugin/format/avro/input/CombineAvroInputFormat*.class|io/cdap/plugin/format/avro/input/PathTrackingAvroInputFormat*.class;scope=compile,!format-avro,*;inline=false;scope=compile</Embed-Dependency>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Fragility Warning: Tight Coupling with format-avro Internals

Hardcoding specific class name patterns (AvroToStructuredTransformer*.class, etc.) in the pom.xml creates a tight coupling with the internal implementation details of format-avro.

The Risk

If format-avro is upgraded in the future (via ${cdap.plugin.version}) and these classes are refactored, renamed, or start depending on new package-private/helper classes within format-avro, the Maven build will still succeed without any errors. However, it will fail at runtime with NoClassDefFoundError or ClassNotFoundException in the OSGi/CDAP environment.

Recommendation

Expand the XML comment to explicitly warn developers about this fragility and instruct them to verify the inlined classes whenever cdap.plugin.version is upgraded.

            <!--
              Inline only the non-@Plugin Avro helper classes used by BigQuery,
              Pub/Sub, and Dataplex so format-avro's dead nested lib/*.jar
              entries are not embedded inside google-cloud.jar!/lib/.

              WARNING: This configuration hardcodes specific class patterns from format-avro.
              If format-avro is upgraded (via cdap.plugin.version) and these classes are
              refactored or new internal dependencies are added, it can cause silent runtime
              NoClassDefFoundErrors. Always verify the inlined classes and their dependencies
              when upgrading cdap.plugin.version.
            -->
            <Embed-Dependency>format-avro;inline=io/cdap/plugin/format/avro/AvroToStructuredTransformer*.class|io/cdap/plugin/format/avro/StructuredToAvroTransformer*.class|io/cdap/plugin/format/avro/input/CombineAvroInputFormat*.class|io/cdap/plugin/format/avro/input/PathTrackingAvroInputFormat*.class;scope=compile,!format-avro,*;inline=false;scope=compile</Embed-Dependency>

This branch has not been deployed

No deployments
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.

1 participant