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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTest.java (-9 / +60 lines)
Lines 259-265 Link Here
259
		"}"
259
		"}"
260
	);
260
	);
261
261
262
	CompilationUnit unit = (CompilationUnit) runConversion(workingCopies[1], true, false, true);
262
	CompilationUnit unit = (CompilationUnit) runConversion(workingCopies[1], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
263
	MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
263
	MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
264
	MethodInvocation methodInvocation = (MethodInvocation) ((ExpressionStatement) methodDeclaration.getBody().statements().get(1)).getExpression();
264
	MethodInvocation methodInvocation = (MethodInvocation) ((ExpressionStatement) methodDeclaration.getBody().statements().get(1)).getExpression();
265
	IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();
265
	IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();
Lines 283-289 Link Here
283
		"	}\n" + 
283
		"	}\n" + 
284
		"}\n";
284
		"}\n";
285
	workingCopies[0] = getWorkingCopy("/Converter15/src/xy/C.java", source);
285
	workingCopies[0] = getWorkingCopy("/Converter15/src/xy/C.java", source);
286
	CompilationUnit unit = (CompilationUnit) runConversion(workingCopies[0], true, false, true);
286
	CompilationUnit unit = (CompilationUnit) runConversion(workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
287
	MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
287
	MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
288
	checkSourceRange(methodDeclaration.getBody(),
288
	checkSourceRange(methodDeclaration.getBody(),
289
		"{\n" + 
289
		"{\n" + 
Lines 301-307 Link Here
301
	"	}\n" + 
301
	"	}\n" + 
302
	"}\n";
302
	"}\n";
303
	workingCopies[0] = getWorkingCopy("/Converter15/src/xy/C.java", source);
303
	workingCopies[0] = getWorkingCopy("/Converter15/src/xy/C.java", source);
304
	CompilationUnit unit = (CompilationUnit) runConversion(workingCopies[0], true, false, true);
304
	CompilationUnit unit = (CompilationUnit) runConversion(workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
305
	MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
305
	MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
306
	checkSourceRange(methodDeclaration.getBody(),
306
	checkSourceRange(methodDeclaration.getBody(),
307
		"{\n" + 
307
		"{\n" + 
Lines 320-326 Link Here
320
	"	}\n" + 
320
	"	}\n" + 
321
	"}\n";
321
	"}\n";
322
	workingCopies[0] = getWorkingCopy("/Converter15/src/test/X.java", source);
322
	workingCopies[0] = getWorkingCopy("/Converter15/src/test/X.java", source);
323
	CompilationUnit unit = (CompilationUnit) runConversion(workingCopies[0], true, false, true);
323
	CompilationUnit unit = (CompilationUnit) runConversion(workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
324
	MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
324
	MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
325
	checkSourceRange(methodDeclaration.getBody(),
325
	checkSourceRange(methodDeclaration.getBody(),
326
		" \n" + 
326
		" \n" + 
Lines 337-343 Link Here
337
	"	}\n" + 
337
	"	}\n" + 
338
	"}\n";
338
	"}\n";
339
	workingCopies[0] = getWorkingCopy("/Converter15/src/test/X.java", source);
339
	workingCopies[0] = getWorkingCopy("/Converter15/src/test/X.java", source);
340
	CompilationUnit unit = (CompilationUnit) runConversion(workingCopies[0], true, false, true);
340
	CompilationUnit unit = (CompilationUnit) runConversion(workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
341
	MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
341
	MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
342
	checkSourceRange(methodDeclaration.getBody(),
342
	checkSourceRange(methodDeclaration.getBody(),
343
		" \n" + 
343
		" \n" + 
Lines 354-360 Link Here
354
	"	}\n" + 
354
	"	}\n" + 
355
	"}\n";
355
	"}\n";
356
	workingCopies[0] = getWorkingCopy("/Converter15/src/test/X.java", source);
356
	workingCopies[0] = getWorkingCopy("/Converter15/src/test/X.java", source);
357
	CompilationUnit unit = (CompilationUnit) runConversion(workingCopies[0], true, false, true);
357
	CompilationUnit unit = (CompilationUnit) runConversion(workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
358
	MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
358
	MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
359
	checkSourceRange(methodDeclaration.getBody(),
359
	checkSourceRange(methodDeclaration.getBody(),
360
		" \n" + 
360
		" \n" + 
Lines 371-377 Link Here
371
	"	}\n" + 
371
	"	}\n" + 
372
	"}\n";
372
	"}\n";
373
	workingCopies[0] = getWorkingCopy("/Converter15/src/test/X.java", source);
373
	workingCopies[0] = getWorkingCopy("/Converter15/src/test/X.java", source);
374
	CompilationUnit unit = (CompilationUnit) runConversion(workingCopies[0], true, false, true);
374
	CompilationUnit unit = (CompilationUnit) runConversion(workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
375
	MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
375
	MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
376
	checkSourceRange(methodDeclaration.getBody(),
376
	checkSourceRange(methodDeclaration.getBody(),
377
		" \n" + 
377
		" \n" + 
Lines 396-402 Link Here
396
		"@interface Annot {}\n"
396
		"@interface Annot {}\n"
397
	);
397
	);
398
398
399
	CompilationUnit unit = (CompilationUnit) runConversion(workingCopies[0], true, false, true);
399
	CompilationUnit unit = (CompilationUnit) runConversion(workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
400
	MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
400
	MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
401
	checkParameterAnnotations(methodDeclaration+" has invalid parameter annotations!",
401
	checkParameterAnnotations(methodDeclaration+" has invalid parameter annotations!",
402
		"----- param 1-----\n" + 
402
		"----- param 1-----\n" + 
Lines 429-435 Link Here
429
		"}"
429
		"}"
430
	);
430
	);
431
431
432
	CompilationUnit unit = (CompilationUnit) runConversion(workingCopies[1], true, false, true);
432
	CompilationUnit unit = (CompilationUnit) runConversion(workingCopies[1], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
433
	MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
433
	MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
434
	MethodInvocation methodInvocation = (MethodInvocation) ((ExpressionStatement) methodDeclaration.getBody().statements().get(0)).getExpression();
434
	MethodInvocation methodInvocation = (MethodInvocation) ((ExpressionStatement) methodDeclaration.getBody().statements().get(0)).getExpression();
435
	checkParameterAnnotations(methodInvocation+" has invalid parameter annotations!",
435
	checkParameterAnnotations(methodInvocation+" has invalid parameter annotations!",
Lines 446-449 Link Here
446
	);
446
	);
447
}
447
}
448
448
449
/**
450
 * @bug 214002: [dom] NPE in MethodBinding.getParameterAnnotations()
451
 * @test Ensures that no NPE occurs when not all method parameters have annotations
452
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=214002"
453
 */
454
public void testBug214002() throws CoreException, IOException {
455
	workingCopies = new ICompilationUnit[1];
456
	workingCopies[0] = getWorkingCopy("/Converter15/src/Test.java",
457
		"public class Test {\n" + 
458
		"	void m(String str, @Bar @Foo Object obj, @Annot int x) {}\n" + 
459
		"}\n" + 
460
		"@interface Foo {}\n" + 
461
		"@interface Bar {}\n" + 
462
		"@interface Annot {}\n"
463
	);
464
465
	CompilationUnit unit = (CompilationUnit) runConversion(workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
466
	MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
467
	checkParameterAnnotations(methodDeclaration+" has invalid parameter annotations!",
468
		"----- param 1-----\n" + 
469
		"----- param 2-----\n" + 
470
		"@LTest~Bar;\n" + 
471
		"@LTest~Foo;\n" + 
472
		"----- param 3-----\n" + 
473
		"@LTest~Annot;\n",
474
		methodDeclaration.resolveBinding()
475
	);
476
}
477
public void testBug214002b() throws CoreException, IOException {
478
	workingCopies = new ICompilationUnit[1];
479
	workingCopies[0] = getWorkingCopy("/Converter15/src/Test.java",
480
		"public class Test {\n" + 
481
		"	void m(@Annot String str, Object obj, @Bar @Foo int x) {}\n" + 
482
		"}\n" + 
483
		"@interface Foo {}\n" + 
484
		"@interface Bar {}\n" + 
485
		"@interface Annot {}\n"
486
	);
487
488
	CompilationUnit unit = (CompilationUnit) runConversion(workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
489
	MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
490
	checkParameterAnnotations(methodDeclaration+" has invalid parameter annotations!",
491
		"----- param 1-----\n" + 
492
		"@LTest~Annot;\n" +
493
		"----- param 2-----\n" + 
494
		"----- param 3-----\n" + 
495
		"@LTest~Bar;\n" + 
496
		"@LTest~Foo;\n",
497
		methodDeclaration.resolveBinding()
498
	);
499
}
449
}
500
}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.java (-1 / +7 lines)
Lines 90-98 Link Here
90
				Argument argument = this.arguments[i];
90
				Argument argument = this.arguments[i];
91
				argument.bind(this.scope, this.binding.parameters[i], used);
91
				argument.bind(this.scope, this.binding.parameters[i], used);
92
				if (argument.annotations != null) {
92
				if (argument.annotations != null) {
93
					if (paramAnnotations == null)
93
					if (paramAnnotations == null) {
94
						paramAnnotations = new AnnotationBinding[length][];
94
						paramAnnotations = new AnnotationBinding[length][];
95
						for (int j=0; j<i; j++) {
96
							paramAnnotations[j] = Binding.NO_ANNOTATIONS;
97
						}
98
					}
95
					paramAnnotations[i] = argument.binding.getAnnotations();
99
					paramAnnotations[i] = argument.binding.getAnnotations();
100
				} else if (paramAnnotations != null) {
101
					paramAnnotations[i] = Binding.NO_ANNOTATIONS;
96
				}
102
				}
97
			}
103
			}
98
			if (paramAnnotations != null)
104
			if (paramAnnotations != null)

Return to bug 214002