You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "homberghp (via GitHub)" <gi...@apache.org> on 2025/06/19 21:06:41 UTC
[PR] prevent attempt to create method that will fail for missing return type [netbeans]
homberghp opened a new pull request, #8605:
URL: https://github.com/apache/netbeans/pull/8605
solves #8594
Implementation:
Add method to test that the return type given is useable by the CreateMethod fix.
Uses that method in 4 places in `CreateElement`.
Added test to verify that no fix is suggested by create element.
Added test data file with minimal working example as given in #8594
---
**^Add meaningful description above**
<details open>
<summary>Click to collapse/expand PR instructions</summary>
By opening a pull request you confirm that, unless explicitly stated otherwise, the changes -
- are all your own work, and you have the right to contribute them.
- are contributed solely under the terms and conditions of the Apache License 2.0 (see section 5 of the license for more information).
Please make sure (eg. `git log`) that all commits have a valid name and email address for you in the Author field.
If you're a first time contributor, see the Contributing guidelines for more information.
If you're a committer, please label the PR before pressing "Create pull request" so that the right test jobs can run.
### PR approval and merge checklist:
1. [ ] Was this PR [correctly labeled](https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=240884239#PRsandYouAreviewerGuide-PRtriggeredCIJobs(conditionalCIpipeline)), did the right tests run? When did they run?
2. [ ] Is this PR [squashed](https://cwiki.apache.org/confluence/display/NETBEANS/git%3A+squash+and+merge)?
3. [ ] Are author name / email address correct? Are [co-authors](https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors#creating-co-authored-commits-on-the-command-line) correctly listed? Do the commit messages need updates?
3. [ ] Does the PR title and description still fit after the Nth iteration? Is the description sufficient to appear in the release notes?
If this PR targets the delivery branch: [don't merge](https://cwiki.apache.org/confluence/display/NETBEANS/Pull+requests+for+delivery). ([full wiki article](https://cwiki.apache.org/confluence/display/NETBEANS/PRs+and+You+-+A+reviewer+Guide))
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] prevent attempt to create method that will fail for missing return type [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on PR #8605:
URL: https://github.com/apache/netbeans/pull/8605#issuecomment-2989589008
> `solves #8594`
you have to pick one of the following keywords for it to work:
https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword ;)
simply edit the PR text and it should update
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] prevent attempt to create method that will fail for missing return type [netbeans]
Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing commented on PR #8605:
URL: https://github.com/apache/netbeans/pull/8605#issuecomment-3508530514
@homberghp this PR looks strange. It lists 199 commits - is this a rebase gone wrong?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] prevent attempt to create method that will fail for missing return type [netbeans]
Posted by "homberghp (via GitHub)" <gi...@apache.org>.
homberghp commented on PR #8605:
URL: https://github.com/apache/netbeans/pull/8605#issuecomment-2989841677
silly me
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] prevent attempt to create method that will fail for missing return type [netbeans]
Posted by "homberghp (via GitHub)" <gi...@apache.org>.
homberghp commented on PR #8605:
URL: https://github.com/apache/netbeans/pull/8605#issuecomment-2995857974
There is still an issue with my test. It passes with the solution in place, but also when I remove the solution by always accepting any value for the returnType. This is no good, since a test is only worth its pay when it becomes red for the proper reason at least once in its life. :disappointed:
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] prevent attempt to create method that will fail for missing return type [netbeans]
Posted by "homberghp (via GitHub)" <gi...@apache.org>.
homberghp commented on PR #8605:
URL: https://github.com/apache/netbeans/pull/8605#issuecomment-3020420494
> There is still an issue with my test. It passes with the solution in place, but also when I remove the solution by always accepting any value for the returnType. This is no good, since a test is only worth its pay when it becomes red for the proper reason at least once in its life. 😞
I have added a test to ensure that the correct fix is proposed when the return type is known.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] prevent attempt to create method that will fail for missing return type [netbeans]
Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing commented on code in PR #8605:
URL: https://github.com/apache/netbeans/pull/8605#discussion_r2404550198
##########
java/java.hints/src/org/netbeans/modules/java/hints/errors/CreateElement.java:
##########
@@ -101,6 +101,17 @@ public final class CreateElement implements ErrorRule<Void> {
private static final int PRIO_TESTSOURCEGROUP = 500;
private static final int PRIO_MAINSOURCEGROUP = 1000;
private static final int PRIO_INNER = 2000;
+
+ /**
+ * Helps to prevent issue 8594, trying to create a method when return type is not given
+ * by using var as the placeholder for the type at the call site.
+ * @param type the TypeMirror that specifies the type info
+ * @return true if fit for create method, false otherwise
+ */
+ private static boolean hasKnownReturnType(TypeMirror type) {
+ if (type==null) return true; // for constructors
+ return type.getKind() != TypeKind.NONE; // none is insufficient info
+ }
Review Comment:
I suggest slightly altered wording and fixing the missing braces for the if construct
```suggestion
/**
* Helps to prevent github issue 8594, trying to create a method when return
* type can't be determined because var is used as placeholder for the type
* at the call
* site.
* @param type the TypeMirror that specifies the type info
* @return true if fit for create method, false otherwise
*/
private static boolean hasKnownReturnType(TypeMirror type) {
// for constructors
if (type == null) {
return true;
}
return type.getKind() != TypeKind.NONE; // none is insufficient info
}
```
##########
java/java.hints/test/unit/src/org/netbeans/modules/java/hints/errors/CreateElementTest.java:
##########
@@ -441,6 +441,21 @@ public void test194625() throws Exception {
"CreateConstructorFix:(java.lang.String string):org.netbeans.test.java.hints.CreateConstructor"
)));
}
+
+ // the test should show that no fix is suggested for a method call where the return type is using the var.
+
Review Comment:
Please remove unnessary whitespace lines (446, 448, 454) and indent line 456 one level (see methods above)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists