Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE when adding LayerEntry relative to the root '/' #2195

Open
briandealwis opened this issue Dec 11, 2019 · 4 comments · May be fixed by #2300
Open

NPE when adding LayerEntry relative to the root '/' #2195

briandealwis opened this issue Dec 11, 2019 · 4 comments · May be fixed by #2300

Comments

@briandealwis
Copy link
Member

Environment:

  • Jib version: jib-core 0.12.0
  • Build tool: cram
  • OS: macOS

Description of the issue:

Seeing NPEs when using jib-core to create a layer with content placed at "/":

Caused by: java.lang.NullPointerException
	at com.google.cloud.tools.jib.image.ReproducibleLayerBuilder$UniqueTarArchiveEntries.add(ReproducibleLayerBuilder.java:75)
	at com.google.cloud.tools.jib.image.ReproducibleLayerBuilder$UniqueTarArchiveEntries.access$100(ReproducibleLayerBuilder.java:47)
	at com.google.cloud.tools.jib.image.ReproducibleLayerBuilder.build(ReproducibleLayerBuilder.java:118)
	at com.google.cloud.tools.jib.builder.steps.BuildAndCacheApplicationLayerStep.call(BuildAndCacheApplicationLayerStep.java:107)
	at com.google.cloud.tools.jib.builder.steps.BuildAndCacheApplicationLayerStep.call(BuildAndCacheApplicationLayerStep.java:37)
	... 6 more

The code in question:

Path namePath = Paths.get(tarArchiveEntry.getName());
if (namePath.getParent() != namePath.getRoot()) {
TarArchiveEntry dir = new TarArchiveEntry(DIRECTORY_FILE, namePath.getParent().toString());
dir.setModTime(LayerConfiguration.DEFAULT_MODIFICATION_TIME.toEpochMilli());

The layer configurations had been built with LayerConfiguration.Builder.addEntryRecursive()

In this case, tarEntryPath.getName() is / (the root directory). namePath is a sun.nio.fs.UnixPath on "/" with filesystem of type sun.nio.fs.MacOSXFileSystem. But namePath.getParent() returns null, which adheres to the contract of Path#getParent(): Returns the parent path, or null if this path does not have a parent.

So an obvious fix is to change this guard to

 if (namePath.getParent() == null || namePath.getParent() != namePath.getRoot()) {

But should we be adding a tar entry for the root directory?

@briandealwis
Copy link
Member Author

Reproducible with java -jar cram-xxx.jar --docker gcr.io/distroless/static image target where target is a directory. This causes target to be placed in /. Specifying target:/path works as /path's parent is not null.

@TadCordle
Copy link
Contributor

I don't think there's any harm in having an explicit entry for /, is there? Maybe we can just go with the quick fix you suggested.

@TadCordle TadCordle added this to the v2.0.0 milestone Dec 16, 2019
@loosebazooka loosebazooka modified the milestones: v2.0.0, v2.1.0 Jan 2, 2020
@loosebazooka
Copy link
Member

Lets not generate this entry: / for now.

@loosebazooka loosebazooka self-assigned this Feb 18, 2020
@loosebazooka loosebazooka modified the milestones: v2.1.0, v2.2.0 Feb 19, 2020
@loosebazooka loosebazooka modified the milestones: v2.2.0, v2.3.0 Apr 14, 2020
@wilx
Copy link

wilx commented May 6, 2020

Adding a directory into "/" was the first thing I tried. It would be nice if this worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants