ReadSheet, ReadWithPartialFilter, ReadWithExactFilter methods - while trying to read an empty sheet it throws an error: “RetrieveSheet: Unknown Error: Attempt to invoke interface method ‘int java.util.List.size()’ on a null object”.
Someone forgot to check if there is any data.
ReadColumn, ReadRow, ReadRange just throw an error “No data found”.
ReadCell just returns empty result.
All methods should return empty data (lists) if there are no data as this is not an error. The way it works no does not allow for checking if we have an empty sheet or cells (ReadRange) or even to search a sheet for specific data (read with filters).
You are correct. I've filed an issue so we can track this.
opened 12:47PM - 10 Sep 26 UTC
bug
issue: accepted
status: forum
affects: ucr
priority: high
android
**Describe the bug**
[From the forum](https://community.appinventor.mit.edu/t/b… ugs-with-reading-data-from-sheets-when-theres-no-data-to-return-empty-sheets-range-built-in-spreadsheet-component/175874?u=ewpatton): The Spreadsheet component throws NPE or other errors when reading an empty sheet, rather than returning an empty list, which is semantically correct.
**Affects**
- [ ] Designer
- [ ] Blocks editor
- [ ] Projects Explorer
- [x] Android Companion
- [ ] iOS Companion
- [x] Android Compiled APK/AAB
- [ ] iOS Compiled IPA
- [ ] Buildserver
- [ ] Debugging
- [ ] Other... (please describe)
**Expected behavior**
The Spreadsheet Read* blocks should return empty lists when the spreadsheet is empty rather than throw. Raising an error would only be appropriate if the spreadsheet didn't exist.
**Steps to reproduce**
The post provides reproducibility details.
1 Like
yashsrv
September 10, 2026, 3:53pm
3
@ewpatton ReadCell returns empty string, I think that’s the expected result?
PS: A fix is here
ucr ← yashsrv:fix/spreadsheet-read-blocks
opened 04:32PM - 10 Sep 26 UTC
**What does this PR accomplish?**
1. ReadRow, ReadColumn, ReadRange, ReadSheet,… ReadWithExactFilter and ReadWithPartialFilter now return empty list when data is empty or null instead of throwing an error.
2. Add a null check in RetrieveSheet method to avoid NPE.
*Testing Guidelines*
1. Connect your SpreadSheet & test these blocks (make sure your Sheet1 is empty)
<img width="492" height="514" alt="image" src="https://github.com/user-attachments/assets/947f9efb-7789-499d-9c05-31605fe6010c" />
2. It should return an empty list now instead of throwing NPE or "No data found"
Fixes #4093
**Context for the changes**
If this PR changes anything related to the companion make sure you have used the `ucr` branch. For all other changes use `master` or provide context for having used a different branch.
See a summary of git branches in the docs: [App Inventor Developer Overview](https://docs.google.com/document/u/1/d/1hIvAtbNx-eiIJcTA2LLPQOawctiGIpnnt0AvfgnKBok/pub#h.g4ai8y7wpbh6)
If your code changes how something works on the device (i.e., it affects the companion):
- [ ] I have made no changes that affect the companion
- [x] I branched from `ucr`
- [x] My pull request has `ucr` as the base
Further, if you've changed the blocks language or another user-facing designer/blocks API (added a SimpleProperty, etc.):
- [ ] I have updated the corresponding version number in appinventor/components/src/.../common/YaVersion.java
- [ ] I have updated the corresponding upgrader in appinventor/appengine/src/.../client/youngandroid/YoungAndroidFormUpgrader.java (components only)
- [ ] I have updated the corresponding entries in appinventor/blocklyeditor/src/versioning.js
For all other changes:
- [x] I have made no changes that affect the master branch
- [ ] I branched from `master`
- [ ] My pull request has `master` as the base
**General items:**
- [ ] I have updated the relevant documentation files under docs/
- [ ] My code follows the:
- [x] [Google Java style guide](https://google.github.io/styleguide/javaguide.html) (for .java files)
- [ ] [Google JavaScript style guide](https://google.github.io/styleguide/jsguide.html) (for .js files)
- [ ] [Swift style guide](https://google.github.io/swift/) (for .swift files)
- [x] Indentation has been doubled checked
- [x] This PR does not include unnecessary changes such as formatting or white space
- [x] `ant tests` passes on my machine
I think it's correct that ReadCell should provide an empty text if there is nothing there. The only exception would be if they attempt to read a cell outside the bounds of the sheet, in which case that should raise an error.
yashsrv
September 11, 2026, 2:17am
5
I tried to read cell A1001 that resulted in an error, so this block is working fine.
Wow, this was really quick.
It works perfectly. All methods now return empty lists without any errors and throw errors only if there’s an actual error (wrong sheet name, range, cell/column/row reference).
2 Likes
yashsrv
September 19, 2026, 5:59pm
8
It feels so good after seeing your response