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

NPE: general enhancements #2223

Open
tobiasKaminsky opened this issue Feb 23, 2018 · 12 comments
Open

NPE: general enhancements #2223

tobiasKaminsky opened this issue Feb 23, 2018 · 12 comments
Labels
approved enhancement performance: NPE 🚫 NullPointerException / Null Pointer Exception

Comments

@tobiasKaminsky
Copy link
Member

From google play console:

Caused by: java.lang.NullPointerException: 
  at com.owncloud.android.ui.activity.FileDisplayActivity$DownloadFinishReceiver.onReceive (FileDisplayActivity.java:1432)

which is
getStorageManager().getFileByPath(mWaitingToSend.getRemotePath())

This method can return null if the file does not exist in our database.

We could

  • add @nullable to method declaration
  • throw IllegalArgumentException, which does not need to be handled
  • throw FileNotFoundException, which needs to be handled

This is just an example, there are a lot more functions where we might return null and then have to check with "returnedObject != null".

This is not something we need to address now and should be discussed on case by case.

@tanvidadu
Copy link
Contributor

I can start working on this issue and add commit for each fix case by case

@tobiasKaminsky
Copy link
Member Author

Thanks @tanvidadu, but we should first clarify what do of the 3 options we use.
What would you prefer?

Sometimes it is even acceptable that no file exists already, e.g. in case of creating a folder...

@tanvidadu
Copy link
Contributor

I prefer option FileNotFoundException as it will allow us to take appropriate action as an when required like display an alert etc.

@tobiasKaminsky
Copy link
Member Author

Here we use the null check on purpose...
But for me a real FileNotFoundException is also the best.

getFileByPath(FileStorageUtils.getParentPath(mRemotePath)) == null){// When parent
// of remote path
// is not created

@mario @AndyScherzinger your opinions?
If we all agree on this, then @tanvidadu can start :-)

@AndyScherzinger
Copy link
Member

I also agree with you @tanvidadu @tobiasKaminsky -> FileNotFoundException is the appropriate one 👍

@tobiasKaminsky
Copy link
Member Author

@tanvidadu if you want to start with this, I am happy to help you.
As you said it is the best to have one commit for each case, so in doubt we can just kill one commit.

@tobiasKaminsky
Copy link
Member Author

So this is happening quite some time according to google play console:

// get 'fresh data' from the database
mLocalFolder = mStorageManager.getFileByPath(mLocalFolder.getRemotePath());
// parse data from remote folder
OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) folderAndFiles.get(0));
remoteFolder.setParentId(mLocalFolder.getParentId());
remoteFolder.setFileId(mLocalFolder.getFileId());

mLocalFolder is null and we did not check this...

@tobiasKaminsky
Copy link
Member Author

mOriginalCurrentAccount = AccountUtils.getCurrentOwnCloudAccount(this).name;

This functions also needs to be handled better :-)

@tobiasKaminsky
Copy link
Member Author

And this...

protected OCFile getCurrentDir() {
OCFile file = getFile();
if (file != null) {
if (file.isFolder()) {
return file;
} else if (getStorageManager() != null) {
String parentPath = file.getParentRemotePath();
return getStorageManager().getFileByPath(parentPath);
}
}
return null;
}

@tanvidadu
Copy link
Contributor

I will start working on the issue. Is there specific action that needs to be taken while handling exception ?

@tobiasKaminsky
Copy link
Member Author

I think it depends on the case

  • some, like creating folder, are needed checks, so they are rather easy
  • some are NPE can be silently catched and ignored
  • some NPE cannot be resolved and should be presented somehow to the user, e.g. if you receive a shared file and a NPE happens (just an example, not sure if this could happen)

If you are unsure, just ask here 👍

@joshtrichards joshtrichards added the performance: general/non-specific lag, ANR, etc and rarer exceptions/errors that don't have their own labels label Oct 19, 2023
@joshtrichards joshtrichards added performance: NPE 🚫 NullPointerException / Null Pointer Exception and removed performance: general/non-specific lag, ANR, etc and rarer exceptions/errors that don't have their own labels labels Dec 20, 2023
@joshtrichards
Copy link
Member

#13084 helped with at least one of these (mLocalFolder)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved enhancement performance: NPE 🚫 NullPointerException / Null Pointer Exception
Projects
None yet
Development

No branches or pull requests

4 participants