GoogleContainerTools/jib · error · IllegalArgumentException

jib.to.tags contains null tag

Error message

jib.to.tags contains null tag

What it means

TargetImageParameters.getTags resolves the set of tags for jib.to.tags. When no list property is configured, it calls tags.get(); a NullPointerException there means a null element was supplied to the tag set, so it is converted into an IllegalArgumentException stating that jib.to.tags contains a null tag.

Source

Thrown at jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/TargetImageParameters.java:81

    this.image.set(image);
  }

  public void setImage(Provider<String> image) {
    this.image.set(image);
  }

  @Input
  @Optional
  public Set<String> getTags() {
    String property = System.getProperty(PropertyNames.TO_TAGS);
    Set<String> tagsValue;
    if (property != null) {
      tagsValue = ImmutableSet.copyOf(ConfigurationPropertyValidator.parseListProperty(property));
    } else {
      try {
        tagsValue = tags.get();
      } catch (NullPointerException ex) {
        throw new IllegalArgumentException("jib.to.tags contains null tag");
      }
    }
    if (tagsValue.stream().anyMatch(str -> str.isEmpty())) {
      throw new IllegalArgumentException("jib.to.tags contains empty tag");
    }
    return tagsValue;
  }

  public void setTags(List<String> tags) {
    this.tags.set(tags);
  }

  public void setTags(Set<String> tags) {
    this.tags.set(tags);
  }

  public void setTags(Provider<Set<String>> tags) {
    this.tags.set(tags);

View on GitHub (pinned to fb949e2676)

Solutions

  1. Remove null entries from the jib.to.tags list before building
  2. Filter with a null-check: tags.findAll { it != null } when constructing the list
  3. Fix the upstream source (property/env/CI variable) that injects a null value
  4. Add a Gradle configuration guard that validates jib.to.tags in afterEvaluate

Example fix

// before
jib.to.tags = ['latest', System.getenv('BUILD_TAG')] // env may be null
// after
jib.to.tags = ['latest', System.getenv('BUILD_TAG')].findAll { it != null }
Defensive patterns

Strategy: type-guard

Validate before calling

def rawTags = jib.to.tags.orNull ?: []
if (rawTags.any { it == null }) {
  throw new GradleException('jib.to.tags must not contain null entries')
}

Type guard

static boolean hasNoNullTags(List<String> tags) {
  tags != null && tags.every { it != null }
}

Try / catch

try {
  def tags = targetImageParameters.tags
} catch (IllegalArgumentException e) {
  if (e.message.contains('null tag')) {
    logger.error('Filter null entries from jib.to.tags before build')
  } else { throw e }
}

Prevention

When it happens

Trigger: Configuring `jib.to.tags = ['latest', null]` (a list containing null), or calling setTags(List.asList(...null...)) / provider supplying a null element, then invoking getTags() during configuration resolution.

Common situations: Programmatically building the tag list from data where a missing tag becomes null; property interpolation producing null entries; tests or plugins assembling tag lists without filtering nulls.

Related errors


AI-assisted analysis of GoogleContainerTools/jib@fb949e2676 (2026-09-06). Data as JSON: /api/errors/642b358682c93990. Report an issue: GitHub.