View | Details | Raw Unified | Return to bug 214647 | Differences between
and this patch

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java (-12 / +18 lines)
Lines 447-467 Link Here
447
	MethodBinding originalMethod = this.original();
447
	MethodBinding originalMethod = this.original();
448
	AnnotationHolder holder = originalMethod.declaringClass.retrieveAnnotationHolder(originalMethod, true);
448
	AnnotationHolder holder = originalMethod.declaringClass.retrieveAnnotationHolder(originalMethod, true);
449
	AnnotationBinding[][] allParameterAnnotations = holder == null ? null : holder.getParameterAnnotations();
449
	AnnotationBinding[][] allParameterAnnotations = holder == null ? null : holder.getParameterAnnotations();
450
	if (allParameterAnnotations == null && (this.tagBits & TagBits.HasParameterAnnotations) != 0) {
450
	if (allParameterAnnotations == null) {
451
		allParameterAnnotations = new AnnotationBinding[length][];
451
		allParameterAnnotations = new AnnotationBinding[length][];
452
		// forward reference to method, where param annotations have not yet been associated to method
452
		if ((this.tagBits & TagBits.HasParameterAnnotations) != 0) {
453
		if (this.declaringClass instanceof SourceTypeBinding) {
453
			// forward reference to method, where param annotations have not yet been associated to method
454
			SourceTypeBinding sourceType = (SourceTypeBinding) this.declaringClass;
454
			if (this.declaringClass instanceof SourceTypeBinding) {
455
			if (sourceType.scope != null) {
455
				SourceTypeBinding sourceType = (SourceTypeBinding) this.declaringClass;
456
				AbstractMethodDeclaration methodDecl = sourceType.scope.referenceType().declarationOf(this);
456
				if (sourceType.scope != null) {
457
				for (int i = 0; i < length; i++) {
457
					AbstractMethodDeclaration methodDecl = sourceType.scope.referenceType().declarationOf(this);
458
					Argument argument = methodDecl.arguments[i];
458
					for (int i = 0; i < length; i++) {
459
					if (argument.annotations != null) {
459
						Argument argument = methodDecl.arguments[i];
460
						ASTNode.resolveAnnotations(methodDecl.scope, argument.annotations, argument.binding);
460
						if (argument.annotations != null) {
461
						allParameterAnnotations[i] = argument.binding.getAnnotations();
461
							ASTNode.resolveAnnotations(methodDecl.scope, argument.annotations, argument.binding);
462
							allParameterAnnotations[i] = argument.binding.getAnnotations();
463
						}
464
					}
465
				} else {
466
					for (int i = 0; i < length; i++) {
467
						allParameterAnnotations[i] = Binding.NO_ANNOTATIONS;
462
					}
468
					}
463
				}
469
				}
464
				this.setParameterAnnotations(allParameterAnnotations);
465
			} else {
470
			} else {
466
				for (int i = 0; i < length; i++) {
471
				for (int i = 0; i < length; i++) {
467
					allParameterAnnotations[i] = Binding.NO_ANNOTATIONS;
472
					allParameterAnnotations[i] = Binding.NO_ANNOTATIONS;
Lines 472-477 Link Here
472
				allParameterAnnotations[i] = Binding.NO_ANNOTATIONS;
477
				allParameterAnnotations[i] = Binding.NO_ANNOTATIONS;
473
			}
478
			}
474
		}
479
		}
480
		this.setParameterAnnotations(allParameterAnnotations);
475
	}
481
	}
476
	return allParameterAnnotations;
482
	return allParameterAnnotations;
477
}
483
}
(-)src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTest.java (-1 / +40 lines)
Lines 40-46 Link Here
40
}
40
}
41
41
42
protected void checkParameterAnnotations(String message, String expected, IMethodBinding methodBinding) {
42
protected void checkParameterAnnotations(String message, String expected, IMethodBinding methodBinding) {
43
	int size = methodBinding.getParameterTypes().length;
43
	ITypeBinding[] parameterTypes = methodBinding.getParameterTypes();
44
	int size = parameterTypes == null ? 0 : parameterTypes.length;
44
	StringBuffer buffer = new StringBuffer();
45
	StringBuffer buffer = new StringBuffer();
45
	for (int i=0; i<size; i++) {
46
	for (int i=0; i<size; i++) {
46
		buffer.append("----- param ");
47
		buffer.append("----- param ");
Lines 497-500 Link Here
497
		methodDeclaration.resolveBinding()
498
		methodDeclaration.resolveBinding()
498
	);
499
	);
499
}
500
}
501
502
/**
503
 * @bug 214647: [dom] NPE in MethodBinding.getParameterAnnotations(..)
504
 * @test Ensures that no NPE occurs when parameters have no annotation
505
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=214647"
506
 */
507
public void testBug214647() throws CoreException, IOException {
508
	workingCopies = new ICompilationUnit[1];
509
	workingCopies[0] = getWorkingCopy("/Converter15/src/Test.java",
510
		"public class Test {\n" + 
511
		"	void m(String str) {}\n" + 
512
		"}\n"
513
	);
514
515
	CompilationUnit unit = (CompilationUnit) runConversion(workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
516
	MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
517
	checkParameterAnnotations(methodDeclaration+" has invalid parameter annotations!",
518
		"----- param 1-----\n",
519
		methodDeclaration.resolveBinding()
520
	);
521
}
522
public void testBug214647b() throws CoreException, IOException {
523
	workingCopies = new ICompilationUnit[1];
524
	workingCopies[0] = getWorkingCopy("/Converter15/src/Test.java",
525
		"public class Test {\n" + 
526
		"	void m(String str, Object o, int x) {}\n" + 
527
		"}\n"
528
	);
529
530
	CompilationUnit unit = (CompilationUnit) runConversion(workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
531
	MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
532
	checkParameterAnnotations(methodDeclaration+" has invalid parameter annotations!",
533
		"----- param 1-----\n" +
534
		"----- param 2-----\n" + 
535
		"----- param 3-----\n",
536
		methodDeclaration.resolveBinding()
537
	);
538
}
500
}
539
}

Return to bug 214647