GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Ternary expression with @MonotonicNonNull fails · Issue #1256 · typetools/checker-framework

Ternary expression with @MonotonicNonNull fails #1256

New issue
Copy link
New issue
Copy link
Closed
#8303
Closed
Ternary expression with @MonotonicNonNull fails#1256
#8303
Copy link
Milestone
Medium

Description

@elcelista
elcelista
opened on Apr 28, 2017
Issue body actions

I would expect the following to check successfully, with bar receiving the inferred type @Nullable Object:

import org.checkerframework.checker.nullness.qual.*;

public class MonotonicNonNullTernaryIf {

  @MonotonicNonNull Object defaultFoo;

  public void test(Object foo, boolean condition) {
    Object bar = condition ? foo : defaultFoo;
  }
}

But instead I get the following error:

$ java -jar checker.jar -processor org.checkerframework.checker.nullness.NullnessChecker -version MonotonicNonNullTernaryIf.java 
javac 1.8.0-jsr308-2.1.10
MonotonicNonNullTernaryIf.java:8: error: [monotonic.type.incompatible] cannot assign org.checkerframework.checker.nullness.qual.MonotonicNonNull to org.checkerframework.checker.nullness.qual.MonotonicNonNull (monotonic type).
    Object bar = condition ? foo : defaultFoo;
                                   ^
  full type found: @Initialized @MonotonicNonNull Object
1 error

Activity

  1. kanha95 commented on May 2, 2017

    @kanha95
    kanha95
    on May 2, 2017
    Contributor
    More actions

    It's similar to Issue #1170.

    import org.checkerframework.checker.nullness.qual.*;
    
    public class MonotonicNonNullTernaryIf {
    
      @MonotonicNonNull Object defaultFoo;
    
      public void test(Object foo, boolean condition) {
        Object bar;
        if(condition) {
            bar=foo;
        }
        else {
        bar=defaultFoo;
          }    
       }
    }

    It passes using if-else statement but fails in case of ternary operators.

  2. mernst commented on May 3, 2017

    @mernst
    mernst
    on May 3, 2017
    Member
    More actions

    A workaround is to use if ... else. This is undesirable, but will work until we fix this issue.

  3. mernst
    added this to the Medium milestone on May 3, 2017
  4. cushon
    added a commit that references this issue on Feb 28, 2026

    Pin JDK 25-ea to build 25.0 (typetools#1256)

    e8d085a
  5. smillst
    closed this as completedin #8303on Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      • MediumNo due date

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.