### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java,v retrieving revision 1.94 diff -u -r1.94 AssistParser.java --- codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java 28 Jul 2010 16:17:04 -0000 1.94 +++ codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java 27 Oct 2010 01:38:02 -0000 @@ -132,8 +132,10 @@ /* Initializer bodies are parsed in the context of the type declaration, we must thus search it inside */ if (this.referenceContext instanceof TypeDeclaration){ TypeDeclaration type = (TypeDeclaration) this.referenceContext; - for (int i = 0; i < type.fields.length; i++){ - FieldDeclaration field = type.fields[i]; + FieldDeclaration[] fields = type.fields; + int length = fields == null ? 0 : fields.length; + for (int i = 0; i < length; i++){ + FieldDeclaration field = fields[i]; if (field != null && field.getKind() == AbstractVariableDeclaration.INITIALIZER && field.declarationSourceStart <= this.scanner.initialPosition Index: compiler/org/eclipse/jdt/internal/compiler/ClassFile.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java,v retrieving revision 1.202 diff -u -r1.202 ClassFile.java --- compiler/org/eclipse/jdt/internal/compiler/ClassFile.java 27 Jul 2010 02:37:05 -0000 1.202 +++ compiler/org/eclipse/jdt/internal/compiler/ClassFile.java 27 Oct 2010 01:38:04 -0000 @@ -1998,7 +1998,7 @@ // report an error and abort: will lead to a problem type classfile creation TypeDeclaration typeDeclaration = this.referenceBinding.scope.referenceContext; FieldDeclaration[] fieldDecls = typeDeclaration.fields; - for (int i = 0, max = fieldDecls.length; i < max; i++) { + for (int i = 0, max = (fieldDecls == null) ? 0 : fieldDecls.length; i < max; i++) { if (fieldDecls[i].binding == fieldBinding) { // problem should abort typeDeclaration.scope.problemReporter().stringConstantIsExceedingUtf8Limit( Index: compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java,v retrieving revision 1.181 diff -u -r1.181 SourceTypeBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java 15 Sep 2010 15:17:25 -0000 1.181 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java 27 Oct 2010 01:38:04 -0000 @@ -166,8 +166,10 @@ FieldBinding existingField; if ((existingField = getField(synthField.name, true /*resolve*/)) != null) { TypeDeclaration typeDecl = this.scope.referenceContext; - for (int i = 0, max = typeDecl.fields.length; i < max; i++) { - FieldDeclaration fieldDecl = typeDecl.fields[i]; + FieldDeclaration[] fieldDeclarations = typeDecl.fields; + int max = fieldDeclarations == null ? 0 : fieldDeclarations.length; + for (int i = 0; i < max; i++) { + FieldDeclaration fieldDecl = fieldDeclarations[i]; if (fieldDecl.binding == existingField) { synthField.name = CharOperation.concat( TypeConstants.SYNTHETIC_OUTER_LOCAL_PREFIX, @@ -210,8 +212,10 @@ FieldBinding existingField; if ((existingField = getField(synthField.name, true /*resolve*/)) != null) { TypeDeclaration typeDecl = this.scope.referenceContext; - for (int i = 0, max = typeDecl.fields.length; i < max; i++) { - FieldDeclaration fieldDecl = typeDecl.fields[i]; + FieldDeclaration[] fieldDeclarations = typeDecl.fields; + int max = fieldDeclarations == null ? 0 : fieldDeclarations.length; + for (int i = 0; i < max; i++) { + FieldDeclaration fieldDecl = fieldDeclarations[i]; if (fieldDecl.binding == existingField) { if (this.scope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_5) { synthField.name = CharOperation.concat( @@ -255,8 +259,10 @@ FieldBinding existingField; if ((existingField = getField(synthField.name, true /*resolve*/)) != null) { TypeDeclaration typeDecl = blockScope.referenceType(); - for (int i = 0, max = typeDecl.fields.length; i < max; i++) { - FieldDeclaration fieldDecl = typeDecl.fields[i]; + FieldDeclaration[] typeDeclarationFields = typeDecl.fields; + int max = typeDeclarationFields == null ? 0 : typeDeclarationFields.length; + for (int i = 0; i < max; i++) { + FieldDeclaration fieldDecl = typeDeclarationFields[i]; if (fieldDecl.binding == existingField) { blockScope.problemReporter().duplicateFieldInType(this, fieldDecl); break; @@ -294,7 +300,8 @@ FieldBinding existingField; if ((existingField = getField(synthField.name, true /*resolve*/)) != null) { TypeDeclaration typeDecl = this.scope.referenceContext; - for (int i = 0, max = typeDecl.fields.length; i < max; i++) { + int max = (typeDecl.fields == null) ? 0 : typeDecl.fields.length; + for (int i = 0; i < max; i++) { FieldDeclaration fieldDecl = typeDecl.fields[i]; if (fieldDecl.binding == existingField) { synthField.name = CharOperation.concat( @@ -337,8 +344,10 @@ FieldBinding existingField; if ((existingField = getField(synthField.name, true /*resolve*/)) != null) { TypeDeclaration typeDecl = this.scope.referenceContext; - for (int i = 0, max = typeDecl.fields.length; i < max; i++) { - FieldDeclaration fieldDecl = typeDecl.fields[i]; + FieldDeclaration[] fieldDeclarations = typeDecl.fields; + int max = fieldDeclarations == null ? 0 : fieldDeclarations.length; + for (int i = 0; i < max; i++) { + FieldDeclaration fieldDecl = fieldDeclarations[i]; if (fieldDecl.binding == existingField) { synthField.name = CharOperation.concat( TypeConstants.SYNTHETIC_ENUM_VALUES, @@ -425,8 +434,10 @@ FieldBinding existingField; if ((existingField = getField(synthField.name, true /*resolve*/)) != null) { TypeDeclaration typeDecl = this.scope.referenceContext; - for (int i = 0, max = typeDecl.fields.length; i < max; i++) { - FieldDeclaration fieldDecl = typeDecl.fields[i]; + FieldDeclaration[] fieldDeclarations = typeDecl.fields; + int max = fieldDeclarations == null ? 0 : fieldDeclarations.length; + for (int i = 0; i < max; i++) { + FieldDeclaration fieldDecl = fieldDeclarations[i]; if (fieldDecl.binding == existingField) { synthField.name = CharOperation.concat( fieldName, @@ -1256,7 +1267,8 @@ if (hasRestrictedAccess()) field.modifiers |= ExtraCompilerModifiers.AccRestrictedAccess; FieldDeclaration[] fieldDecls = this.scope.referenceContext.fields; - for (int f = 0, length = fieldDecls.length; f < length; f++) { + int length = fieldDecls == null ? 0 : fieldDecls.length; + for (int f = 0; f < length; f++) { if (fieldDecls[f].binding != field) continue; Index: compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java,v retrieving revision 1.420 diff -u -r1.420 Parser.java --- compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 28 Jul 2010 16:17:01 -0000 1.420 +++ compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 27 Oct 2010 01:38:08 -0000 @@ -952,8 +952,10 @@ /* Initializer bodies are parsed in the context of the type declaration, we must thus search it inside */ if (this.referenceContext instanceof TypeDeclaration){ TypeDeclaration type = (TypeDeclaration) this.referenceContext; - for (int i = 0; i < type.fields.length; i++){ - FieldDeclaration field = type.fields[i]; + FieldDeclaration[] fieldDeclarations = type.fields; + int length = fieldDeclarations == null ? 0 : fieldDeclarations.length; + for (int i = 0; i < length; i++){ + FieldDeclaration field = fieldDeclarations[i]; if (field != null && field.getKind() == AbstractVariableDeclaration.INITIALIZER && ((Initializer) field).block != null Index: model/org/eclipse/jdt/internal/core/util/HandleFactory.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/HandleFactory.java,v retrieving revision 1.51 diff -u -r1.51 HandleFactory.java --- model/org/eclipse/jdt/internal/core/util/HandleFactory.java 20 May 2010 18:03:14 -0000 1.51 +++ model/org/eclipse/jdt/internal/core/util/HandleFactory.java 27 Oct 2010 01:38:08 -0000 @@ -204,7 +204,8 @@ // inside field or initializer, must find proper one TypeDeclaration type = methodScope.referenceType(); int occurenceCount = 1; - for (int i = 0, length = type.fields.length; i < length; i++) { + int length = type.fields == null ? 0 : type.fields.length; + for (int i = 0; i < length; i++) { FieldDeclaration field = type.fields[i]; if (field.declarationSourceStart <= elementPosition && elementPosition <= field.declarationSourceEnd) { switch (field.getKind()) { Index: search/org/eclipse/jdt/internal/core/search/matching/FieldLocator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/FieldLocator.java,v retrieving revision 1.52 diff -u -r1.52 FieldLocator.java --- search/org/eclipse/jdt/internal/core/search/matching/FieldLocator.java 18 Sep 2008 15:24:57 -0000 1.52 +++ search/org/eclipse/jdt/internal/core/search/matching/FieldLocator.java 27 Oct 2010 01:38:08 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -278,7 +278,8 @@ TypeDeclaration typeDecl = scope.referenceContext; FieldDeclaration fieldDecl = null; FieldDeclaration[] fieldDecls = typeDecl.fields; - for (int i = 0, length = fieldDecls.length; i < length; i++) { + int length = fieldDecls == null ? 0 : fieldDecls.length; + for (int i = 0; i < length; i++) { if (CharOperation.equals(bindingName, fieldDecls[i].name)) { fieldDecl = fieldDecls[i]; break; Index: search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java,v retrieving revision 1.336 diff -u -r1.336 MatchLocator.java --- search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java 7 Sep 2010 19:14:26 -0000 1.336 +++ search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java 27 Oct 2010 01:38:09 -0000 @@ -557,10 +557,11 @@ // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=98378 return type; } - // find occurence count of the given initializer in its type declaration + // find occurrence count of the given initializer in its type declaration int occurrenceCount = 0; FieldDeclaration[] fields = typeDeclaration.fields; - for (int i = 0, length = fields.length; i < length; i++) { + int length = fields == null ? 0 : fields.length; + for (int i = 0; i < length; i++) { if (fields[i].getKind() == AbstractVariableDeclaration.INITIALIZER) { occurrenceCount++; if (fields[i].equals(fieldDeclaration)) break; #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/parser/AbstractCompletionTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/AbstractCompletionTest.java,v retrieving revision 1.24 diff -u -r1.24 AbstractCompletionTest.java --- src/org/eclipse/jdt/core/tests/compiler/parser/AbstractCompletionTest.java 27 Jun 2008 16:04:46 -0000 1.24 +++ src/org/eclipse/jdt/core/tests/compiler/parser/AbstractCompletionTest.java 27 Oct 2010 01:38:10 -0000 @@ -141,9 +141,10 @@ parser.parseBlockStatements((AbstractMethodDeclaration)foundMethod, unit); } else { TypeDeclaration type = (TypeDeclaration)foundMethod; - if (type.fields != null) { - done : for (int i = 0; i < type.fields.length; i++) { - FieldDeclaration field = type.fields[i]; + FieldDeclaration[] fields = type.fields; + if (fields != null) { + done : for (int i = 0; i < fields.length; i++) { + FieldDeclaration field = fields[i]; if (field.declarationSourceStart <= cursorLocation && (cursorLocation <= field.declarationSourceEnd || field.declarationSourceEnd == 0)) { if (field instanceof Initializer) { parser.parseBlockStatements((Initializer)field, type, unit); @@ -359,9 +360,10 @@ } } } - if (type.fields != null) { - for (int i = 0; i < type.fields.length; i++) { - FieldDeclaration field = type.fields[i]; + FieldDeclaration[] fields = type.fields; + if (fields != null) { + for (int i = 0; i < fields.length; i++) { + FieldDeclaration field = fields[i]; if (field instanceof Initializer && field.declarationSourceStart <= cursorLocation && (cursorLocation <= field.declarationSourceEnd || field.declarationSourceEnd == 0)) { return type; } Index: src/org/eclipse/jdt/core/tests/compiler/parser/AbstractSelectionTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/AbstractSelectionTest.java,v retrieving revision 1.19 diff -u -r1.19 AbstractSelectionTest.java --- src/org/eclipse/jdt/core/tests/compiler/parser/AbstractSelectionTest.java 28 Apr 2009 17:17:28 -0000 1.19 +++ src/org/eclipse/jdt/core/tests/compiler/parser/AbstractSelectionTest.java 27 Oct 2010 01:38:10 -0000 @@ -161,9 +161,10 @@ parser.parseBlockStatements((AbstractMethodDeclaration)foundMethod, unit); } else { TypeDeclaration type = (TypeDeclaration)foundMethod; - if (type.fields != null) { - for (int i = 0; i < type.fields.length; i++) { - FieldDeclaration field = type.fields[i]; + FieldDeclaration[] fields = type.fields; + if (fields != null) { + for (int i = 0; i < fields.length; i++) { + FieldDeclaration field = fields[i]; if (field instanceof Initializer && field.sourceStart <= selectionStart && selectionStart <= field.sourceEnd) { parser.parseBlockStatements((Initializer)field, type, unit); break; @@ -283,9 +284,10 @@ } } } - if (type.fields != null) { - for (int i = 0; i < type.fields.length; i++) { - FieldDeclaration field = type.fields[i]; + FieldDeclaration[] fields = type.fields; + if (fields != null) { + for (int i = 0; i < fields.length; i++) { + FieldDeclaration field = fields[i]; if (field instanceof Initializer) { Initializer initializer = (Initializer)field; Block block = initializer.block; #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java,v retrieving revision 1.186 diff -u -r1.186 JavaSearchTests.java --- src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java 10 Feb 2010 09:19:26 -0000 1.186 +++ src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java 27 Oct 2010 01:38:12 -0000 @@ -337,6 +337,21 @@ this.resultCollector); } /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=328554 + */ +public void testDeclarationOfAccessedFields4() throws CoreException { + IMethod method = + getCompilationUnit("JavaSearch", "src", "b10", "A.java"). + getType("A").getMethod("foo", new String[] {}); + searchDeclarationsOfAccessedFields( + method, + this.resultCollector + ); + assertSearchResults( + "", + this.resultCollector); +} +/** * Declaration of referenced types test. */ public void testDeclarationOfReferencedTypes01() throws CoreException { Index: workspace/JavaSearch/src/b10/A.java =================================================================== RCS file: workspace/JavaSearch/src/b10/A.java diff -N workspace/JavaSearch/src/b10/A.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ workspace/JavaSearch/src/b10/A.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,7 @@ +package b10; + +public class A { + int foo() { + return this.i; + } +} \ No newline at end of file