This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Summary: | For loop completion should be intelligent about uninitialized arrays | ||
---|---|---|---|
Product: | java | Reporter: | Petr Hrebejk <phrebejk> |
Component: | Source | Assignee: | Dusan Balek <dbalek> |
Status: | REOPENED --- | ||
Severity: | blocker | CC: | tboudreau |
Priority: | P3 | ||
Version: | 6.x | ||
Hardware: | All | ||
OS: | All | ||
Issue Type: | ENHANCEMENT | Exception Reporter: |
Description
Petr Hrebejk
2006-09-27 18:53:07 UTC
I'm not sure if it is possible to express the described behavior in terms of a single code template definition. However, if an array initialization is your frequently used pattern, you can always define a special tempalte for it. E.g. for (int ${IDX newVarName default="idx"} = 0; ${IDX} < ${ARR array default="arr"}.length; ${IDX}++) { ${ARR}[${IDX}] = ${VALUE default="null"}; } Closing as wontfix. Reopening as an enhancement - if it cannot be expressed in the template language, isn't that a weakness of the template language? It's not so much that I want to generate code that will initialize the array, as that I don't want Node node = addedNodes[i]; to be generated, because it will always be assigning null and the only useful thing to do is delete it. I don't think you need to determine if it is *possible* that the array not be initialized - for a class member that would require flow analysis and it's impossible. But for the case that the array is defined within the scope of the method or static block, it is certainly possible to determine if there is ever assignment to any members of that array (handle simple cases only - i.e. don't try to solve assigning one array variable to another one). The IDE has enough information to get this right most of the time. The fact that the template language doesn't allow for expressing it doesn't mean we shouldn't consider doing it another way. |