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

LeastUpperBoundLogic.lub returns null when matches ConditionalExpr #4036

Closed
challwang opened this issue May 24, 2023 · 1 comment · Fixed by #4137
Closed

LeastUpperBoundLogic.lub returns null when matches ConditionalExpr #4036

challwang opened this issue May 24, 2023 · 1 comment · Fixed by #4137

Comments

@challwang
Copy link

Here is my sample code:

public class TestVO1 {
    private String ccy;
    private BigDecimal amount;

    public String getCcy() { return ccy; }
    public void setCcy(String ccy) { this.ccy = ccy; }
    public BigDecimal getAmount() { return amount; }
    public void setAmount { this.amount = amount; }
}
public class TestDO1 {
    public void calculate() {
        TestVO1 testVO1 = new TestVO1();
        testVO1.setAmount(testVO1.getAmount().setScale(2, testVO1.getCcy().equals("3") ? RoundingMode.HALF_UP : RoundMode.DOWN));
    }
}

Then I use the flying visitor and override the MethodCallExpr visit method

    @Override
    public void visit(MethodCallExpr methodCallExpr, Context context) {
        // some code
        methodCallExpr.resolve();
        // other code
    }

Then com.github.javaparser.ast.Node.getData(Node.java:512) throws an IllegalStateException:

No data of this type found. Use containsData to check for this first.

I debugged into this method: LeastUpperBoundLogic.lub(Set types), this input parameter has 2 items with the same type: java.math.RoundingMode, but they are different objects so the HashSet can not reduce these 2 items and the intersection method can not find the same type either.

So this method returns null at line 101.

@jlerbsc
Copy link
Collaborator

jlerbsc commented May 24, 2023

Thanks for reporting this bug. I can't reproduce your exception (IllegalStateException) but I found that when we calculate the erased candidates which are the intersection of all Erased Super Types sets then the enum members are not considered equal so the intersection is empty and ultimately the returned resolved type is null.

@jlerbsc jlerbsc closed this as completed May 24, 2023
@jlerbsc jlerbsc reopened this May 24, 2023
jlerbsc added a commit that referenced this issue Sep 1, 2023
Fix: issue #4036 LeastUpperBoundLogic.lub returns null when matches ConditionalExpr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants