Skip to content

[Bug]: /table, table(), and tableImage() return wrong results or throw NPEs #5820

@kwvanderlinde

Description

@kwvanderlinde

Describe the Bug

When the /table command encounters a value that does not match any table entry, it does not properly report the failure to find an entry. Instead:

  • If the value is too low, it returns the entry with the lowest minimum for its range
  • If the value is too high, it returns the entry with the greatest maximum for its range
  • If the value is between entries, it throws an NullPointerException

Essentially the same thing happens with the table() and tableImage() macro functions. Notably, getTableEntry() does not share any of this behaviour.

To Reproduce

  1. Create a new campaign.
  2. Add a new table called "test" with these rows:
    • 1 => one
    • 3 => three
  3. In chat, type this: /table test 0. It will print Table test (Anonymous User): one despite not matching.
  4. In chat, type this: /table test 4. It will print Table test (Anonymous User): three. despite not matching.
  5. In chat, type this: /table test 2. It will print this error message:
    Could not execute the command: "table test 2", exception = Cannot invoke "net.rptools.maptool.model.LookupTable$LookupEntry.getValue()" because "result" is null
    
  6. Repeat the same steps using table() and tableImage() instead of /table. These return results for the same table entries as /table, but when passing 2, the error message is even less helpful:
      Error in body of roll.
          Statement options (if any): r
          Statement Body : table("test", 2)
    
    Error trace : chat
    

Expected Behaviour

When the /table command cannot find a matching entry, it should not print anything to chat, i.e., the result should be an empty string. This should hold whether the value is too low, too high, or encounters a gap in the table.

Screenshots

No response

MapTool Info

1.18.5

Desktop

Linux Mint 22.1

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions