GoogleContainerTools / GoogleContainerTools/jib
NPE when adding LayerEntry relative to the root '/'
- Dominant language
- Java
- Stars
- 14.5k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Description
**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:
https://github.com/GoogleContainerTools/jib/blob/a692b8b0cde1f982f6e28309dd08ca80460950e2/jib-core/src/main/java/com/google/cloud/tools/jib/image/ReproducibleLayerBuilder.java#L73-L76
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
```java
if (namePath.getParent() == null || namePath.getParent() != namePath.getRoot()) {
```
But should we be adding a tar entry for the root directory?
Contributor guide
Assessment
This issue has not been assessed yet.