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

Refactor EclipseSourceFileModule to make it more extension-friendly #1382

Merged
merged 4 commits into from
Mar 28, 2024

Conversation

khatchad
Copy link
Contributor

@khatchad khatchad commented Mar 28, 2024

The removed null checks seem to happen further up the class hierarchy. Replace the static construction method with a public constructor. A lone private constructor basically makes it basically impossible to subclass.

The removed null checks seem to happen further up the class hierarchy.
Copy link

github-actions bot commented Mar 28, 2024

Test Results

  572 files  ±0    572 suites  ±0   3h 41m 12s ⏱️ +12s
  734 tests ±0    717 ✅ ±0  17 💤 ±0  0 ❌ ±0 
3 554 runs  ±0  3 467 ✅ ±0  87 💤 ±0  0 ❌ ±0 

Results for commit 1f791e3. ± Comparison against base commit 3a2ca2e.

♻️ This comment has been updated with latest results.

@khatchad khatchad changed the title Make EclipseSourceFileModule more extension-friendly. Refactor EclipseSourceFileModule to make it more extension-friendly. Mar 28, 2024
@khatchad khatchad changed the title Refactor EclipseSourceFileModule to make it more extension-friendly. Refactor EclipseSourceFileModule to make it more extension-friendly Mar 28, 2024
@khatchad khatchad marked this pull request as ready for review March 28, 2024 15:17
Copy link
Member

@msridhar msridhar left a comment

Choose a reason for hiding this comment

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

I understand making the constructor public, but not the removal of the static method and the null checks. Why do we need the latter?

@khatchad
Copy link
Contributor Author

I understand making the constructor public, but not the removal of the static method and the null checks. Why do we need the latter?

I believe that the reason the ctor was originally made private was so that the null check can be enforced. The exception throw couldn't be done in the ctor because super() needs to be the first statement. So, we have the static method invoking a private constructor.

If we make the ctor public, then you don't need the static method because you can simply just call the public ctor. So, I attempted to move the null checks to the ctor. I think this can be done as the null checking actually happens already further up the class hierarchy.

We could keep both the (now public) ctor and the static method, but I don't think anyone would use the latter if the former is available.

private EclipseSourceFileModule(IFile f) {
super(new File(f.getFullPath().toOSString()), f.getName(), null);
public EclipseSourceFileModule(IFile f) {
super(
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment here indicating that passing null to super will cause a failure in the FileModule constructor? We should really get NullAway running on all this code to get rid of this kind of stuff :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does it cause a failure? We would hit this code:

if (f == null) {
throw new IllegalArgumentException("f is null");
}

Which is what we had previously. The only thing that would really be different is that the filename string would be null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or, is the thought that it was clear in this file that an exception would be thrown in this case, and now with the new code, we would need to go two levels up to see the same thing?

Copy link
Member

Choose a reason for hiding this comment

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

My point was that it'd be good to write a comment indicating that we deliberately pass null knowing that there is logic to fail elsewhere, so a reader does not get confused and think it is valid to pass null to the super constructor

@khatchad
Copy link
Contributor Author

I understand making the constructor public, but not the removal of the static method and the null checks. Why do we need the latter?

I believe that the reason the ctor was originally made private was so that the null check can be enforced. The exception throw couldn't be done in the ctor because super() needs to be the first statement. So, we have the static method invoking a private constructor.

If we make the ctor public, then you don't need the static method because you can simply just call the public ctor. So, I attempted to move the null checks to the ctor. I think this can be done as the null checking actually happens already further up the class hierarchy.

We could keep both the (now public) ctor and the static method, but I don't think anyone would use the latter if the former is available.

Perhaps a different way to put it is that it looked like the static method is encapsulating the object construction. But that encapsulation is too strong if we want to subclass.

@khatchad khatchad requested a review from msridhar March 28, 2024 16:19
@msridhar msridhar merged commit ab9f2e2 into wala:master Mar 28, 2024
10 checks passed
@khatchad khatchad deleted the fix_ide branch March 28, 2024 16:44
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.

2 participants