pulumi / pulumi/pulumi-java

Using Output.<T>ofNullable(null) for Integer required properties is casted to zero

Open
#1,075 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area/codegen area/sdks impact/reliability kind/bug
Dominant language
Java
Stars
85
Forks
26
Avg merge
11h 49m
Merged PRs (30d)
22

Description

What happened?

Output.<T>ofNullable(null) is silently casted to 0 when it's used for required integer property.

Expected Behavior

Code will throw error during deployment

Steps to reproduce

App.java

package myproject;

import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.random.RandomInteger;
import com.pulumi.random.RandomIntegerArgs;

public class App {
    public static void main(String[] args) {
        Pulumi.run(ctx -> {

            var maxEmpty = Output.<Integer>ofNullable(null);
            var randomInteger = new RandomInteger("int", RandomIntegerArgs.builder().max(maxEmpty).min(maxEmpty).build());

            ctx.export("exampleOutput", randomInteger.max());
        });
    }
}

build.gradle

plugins {
    id 'application'
}

repositories {
    maven { // The google mirror is less flaky than mavenCentral()
        url("https://maven-central.storage-download.googleapis.com/maven2/")
    }
    mavenCentral()
    mavenLocal()
}

dependencies {
    implementation 'com.pulumi:pulumi:(,1.0]'
    implementation 'com.pulumi:random:4.12.1'
}

application {
    mainClass = project.hasProperty("mainClass")
            ? project.getProperty("mainClass")
            : 'myproject.App'
}
Output of pulumi about
PS D:\MojeProgramy\pulumi-java-testing> pulumi about
CLI          
Version      3.64.0
Go Version   go1.20.3
Go Compiler  gc

Plugins
NAME    VERSION
java    unknown
random  4.12.1

Host
OS       Microsoft Windows 10 Pro
Version  10.0.19044 Build 19044
Arch     x86_64

This project is written in java: executable='C:\Program Files\Microsoft\jdk-17.0.6.10-hotspot\bin\java.exe' version='openjdk 17.0.6 2023-01-17 LTS
OpenJDK Runtime Environment Microsoft-7209853 (build 17.0.6+10-LTS)
OpenJDK 64-Bit Server VM Microsoft-7209853 (build 17.0.6+10-LTS, mixed mode, sharing)' java='C:\Program Files\Microsoft\jdk-17.0.6.10-hotspot\bin\java.exe' javac='17.0.6'

Backend
Name           DESKTOP01
URL            file://~
User           DESKTOP01\XXXXX
Organizations

No dependencies found

Pulumi locates its logs in C:\Users\XXXXX\AppData\Local\Temp by default
Additional context

pulumi stack output

Current stack outputs (1):
    OUTPUT  VALUE
    min     0
Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the case from App.java using the dependencies in build.gradle, then trace how Output.ofNullable(null) reaches the required integer properties. Done means the deployment no longer silently produces 0 and instead reports the invalid null value, with regression coverage for this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.