Repository navigation
Inline only needed format-avro helper classes in OSGi bundle - #1649
bhardwaj-priyanshu wants to merge 1 commit into
Conversation
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.
There was a problem hiding this comment.
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.
| <!-- | ||
| 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> |
There was a problem hiding this comment.
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>
Summary
Updates
maven-bundle-plugin<Embed-Dependency>inpom.xmlto inline only the non-@PluginAvro helper classes used by BigQuery, Pub/Sub, and Dataplex (AvroToStructuredTransformer*.class,StructuredToAvroTransformer*.class,input/CombineAvroInputFormat*.class,input/PathTrackingAvroInputFormat*.class) and excludeformat-avrofromlib/(!format-avro), while keeping all transitive compile dependencies inlib/.Why
format-avrois packaged as an OSGi plugin bundle whose ownlib/*.jarentries cannot be loaded by CDAP's depth-1 plugin unpacker when embedded insidegoogle-cloud-*.jar!/lib/. Inlining only the 6 referenced helper.classfiles (including inner classes) removes 11.3 MB of unreachable nested JARs while keeping runtime classloading identical.Verification
lib/removes onlylib/format-avro-2.13.0.jar(155 -> 154 JARs); all 154 remaininglib/*.jarentries have identical SHA-256 hashes.Export-Package(498 clauses) and@Pluginclass set (29 plugins) are 100% identical..classfiles have identical bytecode SHA-256 toformat-avro-2.13.0.jar, constant-pool scan confirms zero dangling references, and live JDK 11 depth-1URLClassLoaderABI check confirms identical method/constructor signatures.BigQueryAvroConverterTest,PubSub*Test,Dataplex*Test,TestDelegatingGCSOutputCommitter) pass.