-
Notifications
You must be signed in to change notification settings - Fork 207
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
Null check missing for input argument (source) when updating Disassembly view #287
Comments
Hi @LizzMre - sorry for the delay in responding. I thought I had replied, but I must have lost my draft, so here we go from scratch:
I am delighted to received a PR on this issue. Your analysis of the problem looks sound.
Yes, that is a good solution.
That also works, and this option is the minimal change to get rid of the NPE AFAICT.
I don't think there should be a message dialog here. This is because AFAIU this would be a programming error that the user cannot do anything about. Instead I would log the error to the error log. If there is some corrective action the user can take, then displaying the dialog is helpful. It is also suitable to use the dialog if the failure is such that there is no other way to indicate to the user that the displayed values are now incorrect, however I don't think this applies based on your proposal in 1. |
Hi @jonahgraham Thank you for your response! I will take into consideration your suggestions and I will create a PR on this issue. |
Disassembly view is expected to be populated with lines that are fetched from a given source file. There might be the case where instructions on what lines to append are wrong. This results in a null response that will propagate through the code leading to a NPE. The current commit is proofing the code from NPE by: - removing the source position of the lines that were not found within the given file - null checking the source before becoming a key element in the code flow - adding logging if expected lines are not found in the given file Resolves: eclipse-cdt#287
Disassembly view is expected to be populated with lines that are fetched from a given source file. There might be the case where instructions on what lines to append are wrong. This results in a null response that will propagate through the code leading to a NPE. The current commit is proofing the code from NPE by: - removing the source position of the lines that were not found within the given file - null checking the source before becoming a key element in the code flow - adding logging if expected lines are not found in the given file Resolves: eclipse-cdt#287
Disassembly view is expected to be populated with lines that are fetched from a given source file. There might be the case where instructions on what lines to append are wrong. This results in a null response that will propagate through the code leading to a NPE. The current commit is proofing the code from NPE by: - removing the source position of the lines that were not found within the given file - null checking the source before becoming a key element in the code flow - adding logging if expected lines are not found in the given file Resolves: #287
Repo: https://github.com/eclipse-cdt/cdt/tree/main/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/internal/ui/disassembly
Bug Description
Scenario
Let’s consider that we have a Client-Server architecture where the server is sending to the client information on which lines to append to the Disassembly view from a specific file.
There might be a possibility for the server to send some incorrect data, for example: sending additional lines that cannot be found in the associated file.
In this case, the GUI will display a NullPointerException when trying to fetch the lines that don’t exist.
Even though the server might send incorrect data, it would be nice to provide the user a message with a suggestive description of the issue and prevent the GUI from crashing.
Code flow
SourceColorerJob.runInUIThread() -> line 63
Next, the following method will be called:
![image](https://user-images.githubusercontent.com/103601453/219044498-6106899f-199e-4d97-8103-2e9bbc3dbf7f.png)
DisassemblyPart.updateInvalidSource() -> line 1706
From here, for each line (that must be fetched from the file) it will reach the following method: DisassemblyPart.insertSource() -> line 2756 that has multiple blocks of code similar to the sample below:
Sample from this method
![image](https://user-images.githubusercontent.com/103601453/219049200-f1d9d7a3-407f-4d10-bb45-bbd9a16f6413.png)
Bug
![image](https://user-images.githubusercontent.com/103601453/219054758-0cde6a06-1df1-4dfd-a3e6-97eb074296cd.png)
If a line does not exist within the file, SourceFileInfo.getLines() will catch the BadLocationException and return null (See step 4).
The source will be null and sent to DisassemblyDocument.insertSource() (See step 3).
When reaching step 5, there will be a NullPointerException for source.isEmpty() and the GUI will display the following problem:
To Reproduce
The issue has occurred in an isolating case described in the Scenario, but in order to forcingly reproduce the issue, there might be two ways:
Make the source null. Above line 1232 from DisassemblyDocument.insertSource(), we can add source = null;.
Force fetching lines that don't exist in the file. Above line 138 from SourceFileInfo.getLines(), we can add:
int forceOffset = 10;
first = fSource.getNumberOfLines() + forceOffset;
Expected behavior & Potential fix
*According to the string’s externalization guidelines, this might not be approved, but it might be helpful for a user to debug the issue.
Additional information
I would be interested in creating a Pull Request to fix this issue, but I would like a confirmation on the issue described above first. Also, please address me any questions if something is not clear!
Thank you!
The text was updated successfully, but these errors were encountered: