Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: NPE when formatting Ballerina code that includes regular expressions #40541

Closed
lnash94 opened this issue May 30, 2023 · 2 comments · Fixed by #40610
Closed

[Bug]: NPE when formatting Ballerina code that includes regular expressions #40541

lnash94 opened this issue May 30, 2023 · 2 comments · Fixed by #40610
Assignees
Labels
Lang/Regexp Issues related to Ballerina regular expressions Priority/High Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug userCategory/Compilation

Comments

@lnash94
Copy link
Member

lnash94 commented May 30, 2023

Description

Occurred this NPE errors[2] while formatting the below ballerina code[1] using bal format command

[1] sample Ballerina code

import ballerina/constraint;

@constraint:String {pattern: re `[A-Z]{1}`}
public type FlightClass string;

@constraint:String {pattern: re `[a-zA-Z0-9]{3}`}
public type Code string;

public function main() {
    Code code = "A380";
    FlightClass flightclass = "A";
}

[2] Error stack

May 30, 2023 8:57:24 PM org.ballerinalang.formatter.core.FormattingTreeModifier formatNode
SEVERE: Error while formatting [kind: RE_SEQUENCE] [line: 3] [column:33]: java.lang.NullPointerException
May 30, 2023 8:57:24 PM org.ballerinalang.formatter.core.FormattingTreeModifier formatNode
SEVERE: Error while formatting [kind: RE_SEQUENCE] [line: 6] [column:33]: java.lang.NullPointerException
modified files:
/Users/hansaninissanka/Documents/Ballerina Projects/pattern_connector/main.bal

format successful.

Steps to Reproduce

No response

Affected Version(s)

2201.5.0
2201.6.0-rc1

OS, DB, other environment details and versions

No response

Related area

-> Compilation

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@ballerina-bot ballerina-bot added needTriage The issue has to be inspected and labeled manually userCategory/Compilation labels May 30, 2023
@pcnfernando pcnfernando added Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Lang/Regexp Issues related to Ballerina regular expressions and removed needTriage The issue has to be inspected and labeled manually labels May 30, 2023
@pcnfernando
Copy link
Member

The issue seems to be at the TreeModifier when we have a single quantifier. The optional mostTimesMatchedDigit is not handled correctly in https://github.com/ballerina-platform/ballerina-lang/blob/master/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TreeModifier.java#L3612

_ = re `[a-zA-Z0-9]{3}`;

The below works as expected where the optional nodes are available

_ = re `[a-zA-Z0-9]{3,5}`;

We'll consider this a priority and take this up in the next sprint.

@github-actions
Copy link

This issue is NOT closed with a proper Reason/ label. Make sure to add proper reason label before closing. Please add or leave a comment with the proper reason label now.

      - Reason/EngineeringMistake - The issue occurred due to a mistake made in the past.
      - Reason/Regression - The issue has introduced a regression.
      - Reason/MultipleComponentInteraction - Issue occured due to interactions in multiple components.
      - Reason/Complex - Issue occurred due to complex scenario.
      - Reason/Invalid - Issue is invalid.
      - Reason/Other - None of the above cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Lang/Regexp Issues related to Ballerina regular expressions Priority/High Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug userCategory/Compilation
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants