openrewrite / openrewrite/rewrite

Parse and expose nullability of types for use in recipes

Open
#3,221 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement java parser
Dominant language
Java
Stars
3.7k
Forks
570
Avg merge
13h 12m
Merged PRs (30d)
261

Description

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 https://github.com/apache/maven-pmd-plugin/pull/124#issuecomment-1515133417, 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.

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

The issue does not name files, tests, or entry points. Start by locating the type system and recipe APIs, then determine how Kotlin nullability, Java annotations, and inferred nullability could be represented and queried. Done means recipes can access nullability information, initially for a defined subset of these sources.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.