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 — Parse and expose nullability of types for use in recipes · Issue #3221 · openrewrite/rewrite

Parse and expose nullability of types for use in recipes #3221

New issue
Copy link
New issue
Copy link
Open
Open
Parse and expose nullability of types for use in recipes#3221
Copy link
Labels
enhancementNew feature or requestjavaparser

Description

@timtebeek
timtebeek
opened on May 8, 2023
Issue body actions

Kotlin quite clearly has explicit nullability, but some Java projects can somewhat express the same with nullability annotations. In addition to that we can deduce nullabillity once for instance a method has been called on an object.

It would be great if we could capture and expose this information through our type system, such that recipes can query this when inserting code snippets. Notably this came up recently in apache/maven-pmd-plugin#124 (comment), where we want to forgo adding null checks where they are not needed. Ideally this is something we determine ahead of time, even if limited.

Once exposed we can also write clean up recipes that remove excessive null checks. Even if we start small (for instance only looking at Kotlin types, or some nullability annotations, then we can gradually expand this over time, to bring more value to repeatedly running recipes that use this information.

I've not looked at implementation specifics yet, merely discussed this with Knut as it came up recently for Kotlin on Slack.

Activity

  1. timtebeek
    added
    enhancementNew feature or request
    on May 8, 2023
  2. timtebeek
    added this to OpenRewriteon May 8, 2023
  3. timtebeek
    moved this to Backlog in OpenRewriteon May 8, 2023
  4. knutwannheden commented on May 9, 2023

    @knutwannheden
    knutwannheden
    on May 9, 2023
    Contributor
    More actions

    In addition to the nullability information which can be determined from the declarations (Java nullability annotations or Kotlin / TypeScript types) and be amended to the JavaType objects, there is also the aspect of the data flow analysis (e.g. do we know that this variable is null or not null at this point). The latter would have to be computed from the LST using a visitor. Both these sources of information are useful on their own (and can also be developed independently to some extent), but for the full benefit, it would be great if recipes could rely on the combined result of both these components when making a decision on how to generate a certain piece of code.

    Reacted by Tim te Beek
  5. blipper commented on Oct 10, 2024

    @blipper
    blipper
    on Oct 10, 2024
    Contributor
    More actions

    Note that native null restricted and null-types is coming to the language soon. https://openjdk.org/jeps/8303099. After drops https://openjdk.org/jeps/492 so JDK 24/25/26? Probably worth getting started on this sooner rather than later imo.

  6. timtebeek
    added
    java
    parser
    on Apr 6, 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

    enhancementNew feature or requestjavaparser

    Type

    No type

    Projects

    • OpenRewrite
      Status
      Backlog
      Show more project fields

    Milestone

    No milestone

    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.