You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by ne...@apache.org on 2019/07/09 16:42:36 UTC
[netbeans] branch master updated: [NETBEANS-2794] Fix possible
ArrayOutOfBoundException when during refactoring.
This is an automated email from the ASF dual-hosted git repository.
neilcsmith pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new 2db1eb8 [NETBEANS-2794] Fix possible ArrayOutOfBoundException when during refactoring.
new 5489a0e Merge pull request #1365 from lkishalmi/NETBEANS-2794
2db1eb8 is described below
commit 2db1eb8d0290e46ea5c1ff6c7515e1c1c49dadaf
Author: Laszlo Kishalmi <la...@gmail.com>
AuthorDate: Mon Jul 8 19:10:51 2019 -0700
[NETBEANS-2794] Fix possible ArrayOutOfBoundException when during refactoring.
---
.../java/ui/tree/FolderTreeElement.java | 40 ++++++++++++----------
1 file changed, 22 insertions(+), 18 deletions(-)
diff --git a/java/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/tree/FolderTreeElement.java b/java/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/tree/FolderTreeElement.java
index 0a47d88..e9554b5 100644
--- a/java/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/tree/FolderTreeElement.java
+++ b/java/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/tree/FolderTreeElement.java
@@ -19,6 +19,9 @@
package org.netbeans.modules.refactoring.java.ui.tree;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import java.util.logging.Logger;
import javax.lang.model.element.ElementKind;
import javax.swing.Icon;
@@ -36,9 +39,9 @@ import org.openide.util.NbBundle;
*
* @author Jan Becicka
*/
-public class FolderTreeElement implements TreeElement {
+public final class FolderTreeElement implements TreeElement {
- private FileObject fo;
+ private final FileObject fo;
FolderTreeElement(FileObject fo) {
this.fo = fo;
}
@@ -104,22 +107,23 @@ public class FolderTreeElement implements TreeElement {
return null;
}
Sources src = ProjectUtils.getSources(prj);
+ List<SourceGroup> allgroups = new ArrayList<>();
//TODO: needs to be generified
- SourceGroup[] javagroups = src.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
- SourceGroup[] xmlgroups = src.getSourceGroups("xml");//NOI18N
-
- SourceGroup[] allgroups = new SourceGroup[javagroups.length + xmlgroups.length];
-
- if (allgroups.length < 1) {
+ String[] sourceTypes = new String[] {
+ JavaProjectConstants.SOURCES_TYPE_JAVA,
+ "xml", //NOI18N
+ };
+ for (String sourceType : sourceTypes) {
+ allgroups.addAll(Arrays.asList(src.getSourceGroups(sourceType)));
+ }
+ if (allgroups.isEmpty()) {
// Unknown project group
Logger.getLogger(FolderTreeElement.class.getName()).severe("Cannot find SourceGroup for " + file.getPath()); // NOI18N
return null;
- }
- System.arraycopy(javagroups,0,allgroups,0,javagroups.length);
- System.arraycopy(xmlgroups,0,allgroups,allgroups.length-1,xmlgroups.length);
- for(int i=0; i<allgroups.length; i++) {
- if (allgroups[i].getRootFolder().equals(file) || FileUtil.isParentOf(allgroups[i].getRootFolder(), file)) {
- return allgroups[i];
+ }
+ for (SourceGroup group : allgroups) {
+ if (group.getRootFolder().equals(file) || FileUtil.isParentOf(group.getRootFolder(), file)) {
+ return group;
}
}
return null;
@@ -132,10 +136,10 @@ public class FolderTreeElement implements TreeElement {
}
Sources src = ProjectUtils.getSources(prj);
SourceGroup[] javagroups = src.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
-
- for(int i=0; i<javagroups.length; i++) {
- if (javagroups[i].getRootFolder().equals(file) || FileUtil.isParentOf(javagroups[i].getRootFolder(), file)) {
- return javagroups[i];
+
+ for (SourceGroup group : javagroups) {
+ if (group.getRootFolder().equals(file) || FileUtil.isParentOf(group.getRootFolder(), file)) {
+ return group;
}
}
return null;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists