NPE in `StaticClassExpr.getClassWhere` when a property argument is an arithmetic expression of two parameters (`f(i + k)`, `f(i + i)`)

Open
#1,902 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
java
Domain
backend

Research direction

Start with StaticClassExpr.getClassWhere at StaticClassExpr.java:23 and trace how FormulaExpr.getStaticClass() supplies the class for property arguments. Reproduce with the provided line(i + i) example using nonempty data; empty data masks the failure. Done means arithmetic arguments no longer throw an NPE and the date arithmetic cases return the expected value or type.

Written by the indexing model from the issue text.

Description

Steps to reproduce

Run as an eval script (POST /eval, module mode with run()), or put it into any module and call the action:

line = DATA LOCAL STRING (INTEGER);

run() {
    line(1) <- 'a';
    line(2) <- 'b';
    EXPORT JSON FROM c = (GROUP SUM 1 IF line(INTEGER i) AND line(i + i));
}
Expected

{"c":1} (for i = 1, line(2) is set).

Actual
java.lang.NullPointerException: Cannot invoke "lsfusion.server.logics.classes.ConcreteClass.inSet(lsfusion.server.logics.classes.user.set.AndClassSet)" because the return value of "lsfusion.server.data.expr.classes.StaticClassExprInterface.getStaticClass()" is null
        at lsfusion.server.data.expr.classes.StaticClassExpr.getClassWhere(StaticClassExpr.java:23)
        at lsfusion.server.data.expr.classes.StaticClassExpr.getClassWhere(StaticClassExpr.java:26)
        at lsfusion.server.data.where.classes.ClassWhere.mapClasses(ClassWhere.java:98)
        at lsfusion.server.data.table.Table$Join$IsIn.calculateClassWhere(Table.java:548)
        at lsfusion.server.data.where.AbstractWhere.getClassWhere(AbstractWhere.java:173)
        at lsfusion.server.data.where.DataWhere.create(DataWhere.java:89)
        at lsfusion.server.data.table.Table$Join.getWhere(Table.java:410)
        at lsfusion.server.data.table.Table$Join$IsIn.translate(Table.java:525)
        at lsfusion.server.data.expr.where.ifs.IfExpr.translate(IfExpr.java:204)
        at lsfusion.server.data.query.translate.QueryTranslateJoin.getExpr(QueryTranslateJoin.java:28)
        at lsfusion.server.data.query.translate.RemapJoin.getExpr(RemapJoin.java:21)
        at lsfusion.server.logics.property.Property.getQueryExpr(Property.java:2398)
        ...
Scope

Checked on 44 variants. The results on 6.3 and 7.0 are identical; the stored property was checked on 7.0 only.

Fails

  • Argument forms: line(i + k), line(k + i), line(i - k), line(i * k), line(i (+) k), and line(i + i) with a single parameter.
  • It fails however the second parameter is bounded: iterate(k, 1, 2), another local property, or k >= 1 AND k <= 2. It fails even for an empty iterate(k, 1, 0).
  • Contexts: GROUP SUM, GROUP MIN, EXPORT ... WHERE, <- ... WHERE, FOR.
  • Key classes: INTEGER, LONG, NUMERIC, DOUBLE, STRING (lineS(a + b)), and mixed INTEGER + LONG.
  • Properties: any DATA LOCAL, a stored DATA property, and a calculated property over it (len(INTEGER x) = length(line(x))).
    Works
  • Arguments with a constant or a cast: line(i + k + 1), line(i + k + 0), line(INTEGER(i + k)), line(i + 1), line(k + 1); the same with NUMERIC keys and with strings (lineS(a + b + '')).
  • A constant of another class than the key: a LONG or NUMERIC key with line(i + 1), where i is INTEGER.
  • i + k outside a property argument: i + k > 0, GROUP MAX (i + k).
  • A pure formula property without a table: sq(INTEGER x) = x * x, then sq(i + k); also sum(d, k) for dates.

Masked on empty data: if the local property has no rows, there is no error and the result is 0, so a test on empty data passes.

Related: date arithmetic in 7.0

In 7.0, + and - work for dates, and the value of d + 1 is correct. But its class is INTEGER: e = d + 1 with a DATE e does not compile (value of class 'DATE' is not comparable with value of class 'INTEGER'). As an argument of a property with a DATE key, it gives an empty result without any error:

lineD = DATA LOCAL STRING (DATE);

run() {
    lineD(2026_10_01) <- 'a';
    lineD(2026_10_02) <- 'b';
    lineD(2026_10_03) <- 'c';
    EXPORT JSON FROM d = DATE d, v = (d + 1), plus1 = lineD(d + 1), cast1 = lineD(DATE(d + 1)) WHERE lineD(d);
}

Expected: plus1 = b and c for 2026-10-01 and 2026-10-02, the same as cast1.
Actual: v is correct (2026-10-02, 2026-10-03, 2026-10-04), cast1 = b, c, plus1 is empty in every row.

  • lineD(d + k), line(a - b) (DATE − DATE): the same NPE.
  • lineD(d + 1), lineD(d - 1), lineD(d + k + 0): empty result, no error.
  • lineD(DATE(d + k)), lineD(sum(d, k)): correct.
Possible cause

FormulaExpr.getStaticClass() calls getStaticClass(null), which takes getSelfType(), the type computed without the classes of the keys. For an expression built only from keys, this type is null, and StaticClassExpr.getClassWhere calls inSet on it without a null check. With a constant, the type seems to come from the constant, so d + 1 gets INTEGER instead of DATE, and the class check against a DATE key fails. This code is the same in 6.3 and 7.0.

Suggested label: bug

Dominant language
Java
Stars
214
Forks
46
PR merge metrics
No merged PRs in 30d

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No 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.

More from lsfusion/platform

All issues in lsfusion/platform

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.