felix-atomos icon indicating copy to clipboard operation
felix-atomos copied to clipboard

Don't add parent packages, only the ones that are actually present

Open bosschaert opened this issue 2 years ago • 5 comments

Previously the code added all the packages, also packages which were just found as parent directories in the Jar file. As packages aren't hierarchical this isn't correct. Only packages in which .class files are found should be added.

bosschaert avatar Dec 21 '23 15:12 bosschaert

What problem does this pose? I worry about packages they may contain resource only.

tjwatson avatar Jan 02 '24 15:01 tjwatson

I think the actual problem is that it currently adds directories - that makes it so that packages get claimed for a bundle that actually only has a sub-package. Let's say we have a bundle A with org/foo/Foo.class and bundle B with org/foo/bar/Bar.class. We don't want bundle B to be identified for the org.foo package (only for the org.foo.bar package). In other words, I guess I agree that the requirement for a .class file is too strong - it would be better to just require something else than a dir (i.e., filtering out all directories).

karlpauls avatar Jan 02 '24 19:01 karlpauls

I see it adding too many directories with only other sub-directories (no files) , but I am unclear what observable consequence there is to this.

Refreshing my memory of this, the code only reads from this map packageToAtomosContent in the method org.apache.felix.atomos.impl.base.AtomosBase.getAtomosKey(Class<?>). So it will only really be used for looking up a package name that actually has a loaded Class. What I think the observable consequence may be is when a parent package is contained in another bundle and the order is such that the bundle with the child package is processed first and there for takes over the map entry for that package name. Is that something you all ran into when discovering this issue?

tjwatson avatar Jan 03 '24 14:01 tjwatson

when a parent package is contained in another bundle and the order is such that the bundle with the child package is processed first and there for takes over the map entry for that package name.

I've observed this exact problem when bnd's JPMS plugin was over stocking a module description with "packages" of empty dirs. However, you need to account for both resources and class files alike when computing what is a package and what is not.

.. and yet even this can go wrong. Think of jars which include schema files from other projects (looking at you JavaEE/Jakata and friends) so you should leave some form of escape hatch.

rotty3000 avatar Jan 03 '24 15:01 rotty3000

Yes, the issue is that it is used for the lookup of the bundle that provides a given class (via FrameworkUtils). So in my scenario above, if bundle B gets the spot for org.foo it is returned for the bundle lookup of the Foo.class via FrameworkUtil.

karlpauls avatar Jan 03 '24 15:01 karlpauls