Skip to content

Handle null case return values of methods getBuildData getTargetPlatformData for implementations of class CConfigurationData #577

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

Closed
wants to merge 8 commits into from

Conversation

jantje
Copy link
Contributor

@jantje jantje commented Sep 26, 2023

These are some cases I found where null pointer exceptions were thrown due to implementations of getBuildData and getTargetPlatformData from abstract class CConfigurationData returning null.

jantje and others added 8 commits May 31, 2023 04:49
I don't really like this but it is the best I could come up with
This does not work because the project folder is added in front of the
${ProjectName}after pressing ok when having "is workspace" selected
(which is default after  pressing "add workspace folder")


of implementations of class CConfigurationData
@jonahgraham
Copy link
Member

I restarted the build to see if the failure was intermittent.

@Torbjorn-Svensson
Copy link
Member

@jantje Do you plan to squash the commits or have them as individual commits in the git log? If the latter, can you please make sure that each of the commits contain a more descriptive comment of what the change is really doing and why?
Also, please don't include merge commits in the PR.

@jantje
Copy link
Contributor Author

jantje commented Sep 27, 2023

Do you plan to squash the commits or have them as individual commits in the git log?

I have no clue what you are talking about.

Also, please don't include merge commits in the PR.

I was surprised to see that. I thought a PR only checked differences between the 2 branches.

So basically: I don't know what I'm doing on regards of github commits/PR.
If you want me to do something you will have to be very explicit in what I need to do.

@jonahgraham
Copy link
Member

No worries. We can review the full diff to main branch and squash and merge later if ready to submit.

I'm unsure about the change. Would it be better to make this (undocumented) API just return non-null by design? Or does it really need to return null?

@jantje
Copy link
Contributor Author

jantje commented Sep 27, 2023

This is about CDT accepting null values from implementers of the undocumented API.
Basically CDT extensions using the undocumented API (like autoBuild and managedBuild do) need to extend CConfigurationData and as such implement getBuildData and getTargetPlatformData.
In the current implementation; if the extensions of CConfigurationData return null on these methods CDT will throw null exceptions. This pull requests avoids the null exceptions I have met during my testing.

The main reason I created this pull request is:
If I remember correctly someone told me he would love to get rid of CTargetPlatformData.
I think the first step is to allow CDT extensions to return null; as I find myself in the situation of having done some work in that area I though; lets make a pull request.

Another good reasons is:
Trouble shooting. I had implemented proper implementations for getBuildData and getTargetPlatformData but I was unsure if these "proper implementations" caused #356. Providing null values showed me that the problem exists elsewhere (or also elsewhere).
Other people ever being so crazy like me

  • to try to do what I am doing may be helped the same way.
  • will be able to get away with retuning null in getBuildData and getTargetPlatformData until they are forced to implement them for other reasons.

I will not be offended if you do not accept this pull request. I didn't put in mutch effort nor does it make CDT better for the user. I do not think Autobuild can drop CBuildData but maybe Autobuild can work without CTargetPlatformData if CDT is willing to accept this pull request.

PS I really have no clue why my previous pull request content is in this pull request. Basically this is only about the last commit d5788a8

@@ -299,7 +300,7 @@ protected IProxyProvider createChildProxyProvider() {
@Override
public CDataObject[] getChildren() {
CConfigurationData data = getConfigurationData(false);
List<CDataObject> list = new ArrayList<>();
Set<CDataObject> list = new HashSet<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the order of importance? If so, then using a Set will not work here.

@@ -74,7 +74,7 @@ public ICSettingObject getSetting() {

@Override
public int getSettingType() {
return fSetting.getType();
return fSetting == null ? 0 : fSetting.getType();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does 0 mean here?
Is it safe to always return this value in the absence of fSetting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The int is a flag where each bit is an attribute that is (not)set.
0 as such means no flags set.
Is this safe? I think so because fSetting is never null in the current code.
If fSettings is null the current code throws an exception.

Comment on lines +1926 to +1930
} else {
if (newBuildSetting != oldBuildSetting) {
delta.addChangeFlags(ICDescriptionDelta.ERROR_PARSER_IDS);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else {
if (newBuildSetting != oldBuildSetting) {
delta.addChangeFlags(ICDescriptionDelta.ERROR_PARSER_IDS);
}
}
} else if (newBuildSetting != oldBuildSetting) {
delta.addChangeFlags(ICDescriptionDelta.ERROR_PARSER_IDS);
}

Comment on lines +1941 to +1945
} else {
if (newTPS != oldTPS) {
delta.addChangeFlags(ICDescriptionDelta.ERROR_PARSER_IDS);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else {
if (newTPS != oldTPS) {
delta.addChangeFlags(ICDescriptionDelta.ERROR_PARSER_IDS);
}
}
} else if (newTPS != oldTPS) {
delta.addChangeFlags(ICDescriptionDelta.ERROR_PARSER_IDS);
}

Comment on lines +157 to +159
if (fBuildData != null) {
((CBuildSettingCache) fBuildData).initEnvironmentCache();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (fBuildData != null) {
((CBuildSettingCache) fBuildData).initEnvironmentCache();
}
if (fBuildData != null && fBuildData instanceof CBuildSettingCache) {
((CBuildSettingCache) fBuildData).initEnvironmentCache();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is a code change that has nothing to do with null values.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought you were trying to make the code base a little bit more robust, but perhaps I misread what you were aiming at.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only wanted to note that this change does not match the title (capability to handle null values).
I do not feel competent enough in java nor boolean logic to validate if this change is more robust or not but it does look like it to me.
I described the aim of the change here: #577 (comment)

@@ -105,9 +105,17 @@ protected void copySettingsFrom(CConfigurationData base, boolean clone) {
return;
fDescription = base.getDescription();

fTargetPlatformData = copyTargetPlatformData(base.getTargetPlatformData(), clone);
if (base.getTargetPlatformData() != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be cleaner to have the null-check in the copyTargetPlatformData and copyBuildData functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaning the code is indeed something that needs to be done. We fully agree on that.
The current code is simply not readable nor understandable for someone with my skill level.
I tried to make the changes very clear, readable, straightforward and safe.
In this case I think code that says: "When there is a targetplatform copy it and assign to x else assign null to x." is way more readable than
Having a copytargetplatform which returns a copy when the source targetplatform is not null and null when the source targetplatform is null.

But it is core CDT code and as such not my call.

@Torbjorn-Svensson
Copy link
Member

Torbjorn-Svensson commented Sep 30, 2023

PS I really have no clue why my previous pull request content is in this pull request. Basically this is only about the last commit d5788a8

You need to rebase your modification on top of the main branch of this repository and drop the merge commits to get it right.

I suppose this is easily done by:

git fetch origin
git checkout origin/main
git cherry-pick d5788a81d29da3aa0a79af2cddcb4f9eca58f4ba
# resolve any potential conflicts here...
git push jantje --force HEAD:refs/heads/handle_null_cases

The above assumes that origin is https://github.com/eclipse-cdt/cdt and jantje is https://github.com/jantje/cdt

@jantje
Copy link
Contributor Author

jantje commented Sep 30, 2023

You need to rebase your modification on top of the main branch of this repository and drop the merge commits to get it right.

I suppose this is easitly done by:

git fetch origin
git checkout origin/main
git cherry-pick d5788a81d29da3aa0a79af2cddcb4f9eca58f4ba
# resolve any potential conflicts here...
git push jantje --force HEAD:refs/heads/handle_null_cases

The above assumes that origin is https://github.com/eclipse-cdt/cdt and jantje is https://github.com/jantje/cdt

Thanks for the input but at least 2 of your assumptions are wrong.
1)I use e-git and not the command line
2)As I forked https://github.com/eclipse-cdt/cdt at github and then imported https://github.com/jantje/cdt in eclipse my origin is https://github.com/jantje/cdt
afbeelding

As to the origin.
IMHO if I knew how to change the origin to https://github.com/eclipse-cdt/cdt I would not be able to push my changes to github as I do not have write access to the CDT repository.
As I have 3 systems I use for development; that would mean I would be seriously handicapped each time I'm forced to touch CDT code; for instance changes to investigate behaviour or changes to exclude code (like this PR).
I try to limit CDT pull requests to the absolute minimum because I spend way more time on trying to contribute to eclipse than finding a workaround and it nearly always ends up in being an emotional drain because we seem to live on different planets.

As to using command line git.

git cherry-pick d5788a8

I assume that number is not a constant so how do I get it?

resolve any potential conflicts here...

Again my lack of skills lead me to workarounds. I hardly know how to solve conflicts.
So I synch at the github level when I change CDT code (If I didn't forget)
afbeelding
Then do a pull request. And go from there. Given my experiences with the previous PR I now also created a branch.
I'm very well aware this is not a good way to work. But if eclipse is serious about "contributors" a basic document describing how to contribute code -as a non eclipse community member- would be appreciated.

@Torbjorn-Svensson
Copy link
Member

You need to rebase your modification on top of the main branch of this repository and drop the merge commits to get it right.
I suppose this is easitly done by:

git fetch origin
git checkout origin/main
git cherry-pick d5788a81d29da3aa0a79af2cddcb4f9eca58f4ba
# resolve any potential conflicts here...
git push jantje --force HEAD:refs/heads/handle_null_cases

The above assumes that origin is https://github.com/eclipse-cdt/cdt and jantje is https://github.com/jantje/cdt

Thanks for the input but at least 2 of your assumptions are wrong. 1)I use e-git and not the command line 2)As I forked https://github.com/eclipse-cdt/cdt at github and then imported https://github.com/jantje/cdt in eclipse my origin is https://github.com/jantje/cdt
afbeelding

I wouldn't say that my assumptions were wrong, it's just that you need to adapt it to your situation.

As I'm in a sharing mod, here are the commands that you could use on the command line. I leave it to you to translate those to e-git as I've not used it and have no desire to learn how to use it.

git fetch origin
git checkout origin/main
git cherry-pick d5788a81d29da3aa0a79af2cddcb4f9eca58f4ba
# resolve any potential conflicts here...
git push origin --force HEAD:refs/heads/handle_null_cases

Note: This assumes that your fork is up to date with https://github.com/eclipse-cdt/cdt., if it's not, then you need to sync it first.

As to the origin. IMHO if I knew how to change the origin to https://github.com/eclipse-cdt/cdt I would not be able to push my changes to github as I do not have write access to the CDT repository. As I have 3 systems I use for development; that would mean I would be seriously handicapped each time I'm forced to touch CDT code; for instance changes to investigate behaviour or changes to exclude code (like this PR). I try to limit CDT pull requests to the absolute minimum because I spend way more time on trying to contribute to eclipse than finding a workaround and it nearly always ends up in being an emotional drain because we seem to live on different planets.

As to using command line git.

git cherry-pick d5788a8

I assume that number is not a constant so how do I get it?

Well, it was you that added that commit id in the previous comment, but you can see that using git log in the command line. I have no idea where you see it in e-git.

resolve any potential conflicts here...

Again my lack of skills lead me to workarounds. I hardly know how to solve conflicts. So I synch at the github level when I change CDT code (If I didn't forget) afbeelding Then do a pull request. And go from there.

Regardless if you sync your fork before you start or not, there might be changes later on during your PR's lifetime that will need to be addressed. It's not like you do one modification, create the PR and then your done. You're not done before the PR was merged or closed otherwise.

Given my experiences with the previous PR I now also created a branch. I'm very well aware this is not a good way to work. But if eclipse is serious about "contributors" a basic document describing how to contribute code -as a non eclipse community member- would be appreciated.

There is absolutely no difference if you are an "Eclipse community member" or not, you do the same procedure.
I.e.

  1. Do the change locally and verify that it works.
  2. Push the change to some branch, can be main, can be something completely different, on your forked repository.
  3. Go to your forked repository at https://github.com and open a PR to the upstream repository.

@jantje
Copy link
Contributor Author

jantje commented Oct 1, 2023

I leave it to you to translate those to e-git as I've not used it and have no desire to learn how to use it.

I feel you. I feel the same about learning git command line.

git cherry-pick d5788a8

I assume that number is not a constant so how do I get it?

Well, it was you that added that commit id in the previous comment, but you can see that using git log in the command line. I have no idea where you see it in e-git.

So the answer is: it is the commit id. Thanks for that.

It's not like you do one modification, create the PR and then your done. You're not done before the PR was merged or closed otherwise.

Well in my case in regards to CDT (the only repository I contribute to which is not mine) it basically is that.
As CDT is not my main code line I mostly start changing stuff inside CDT to investigate.
Most of the time I find I learned something; undo my changes and modify my code.
Sometimes (like in this case) I think the CDT team may be interested in some of the changes and I go to the effort of creating a PR to give back to CDT.
Very rarely I find there is actually a bug in CDT (In many cases I think there is one and then later I find there isn't one or it is elsewhere in eclipse) that needs fixing (read I can't work around in my code). The only actual bug(?) I fixed I can recall -from the top of my head- is the upper-casing of environment variable names. But was that a bug?
So from my point of view the most PR's I'm offering are "here I did this; take it or leave it; I don't care". Just like this one is.
If I count the time that has been spend contributing to this issue (without counting the time people spend reading this stuff) I think that is at least 100 times the time spend on the actual code changes. And that makes me sad.
I don't want to use our time on trivial code changes.
I know my skill level of java and git is to low to be a considered a eclipse contributor, I say so at numerous places.
I can only offer you what I think may be of interest.
Please feel free to throw it away or polish it to your likings.
But let us not lose time over "how I should have done better" or "what I think the polished version should look like"
If I should have done better there should be a reference to a document that explains how to do so.
And on the polishing; Yes I didn't think of the order when changing to Set; I'm really happy CDT core continues improving the CDT code quality but I can't evaluate changes; I'm only using a very narrow slice of CDT/eclipse and java.

@jonahgraham
Copy link
Member

I am cleaning up our backlog of open Pull Requests. Please re-open this PR if you plan to pick up this work again soon.

@jantje jantje deleted the handle_null_cases_#575 branch January 5, 2024 02:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants