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

Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java (+48 lines)
Lines 2374-2379 Link Here
2374
			"SUCCESS"
2374
			"SUCCESS"
2375
		);
2375
		);
2376
}
2376
}
2377
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=359284
2378
// Verify that checkcast is emitted for a cast expression.
2379
public void test061b() throws Exception {
2380
	String source =
2381
		"public class X {\n" +
2382
	    "public X() {\n" +
2383
	    "    Object[] x = (Object[])null;\n" +
2384
	    "}\n" +
2385
	    "}\n";
2386
	this.runConformTest(
2387
			new String[] {
2388
				"X.java",
2389
				source
2390
			},
2391
			""
2392
		);
2393
	String expectedOutput = 
2394
			"public class X {\n" + 
2395
			"  \n" + 
2396
			"  // Method descriptor #6 ()V\n" + 
2397
			"  // Stack: 1, Locals: 2\n" + 
2398
			"  public X();\n" + 
2399
			"     0  aload_0 [this]\n" + 
2400
			"     1  invokespecial java.lang.Object() [8]\n" + 
2401
			"     4  aconst_null\n" + 
2402
			"     5  checkcast java.lang.Object[] [10]\n" + 
2403
			"     8  astore_1 [x]\n" + 
2404
			"     9  return\n" + 
2405
			"      Line numbers:\n" + 
2406
			"        [pc: 0, line: 2]\n" + 
2407
			"        [pc: 4, line: 3]\n" + 
2408
			"        [pc: 9, line: 4]\n" + 
2409
			"      Local variable table:\n" + 
2410
			"        [pc: 0, pc: 10] local: this index: 0 type: X\n" + 
2411
			"        [pc: 9, pc: 10] local: x index: 1 type: java.lang.Object[]\n" +
2412
			"}";
2413
	File f = new File(OUTPUT_DIR + File.separator + "X.class");
2414
	byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f);
2415
	ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
2416
	String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED);
2417
	int index = result.indexOf(expectedOutput);
2418
	if (index == -1 || expectedOutput.length() == 0) {
2419
		System.out.println(Util.displayString(result, 3));
2420
	}
2421
	if (index == -1) {
2422
		assertEquals("Wrong contents", expectedOutput, result);
2423
	}
2424
}
2377
public static Class testClass() {
2425
public static Class testClass() {
2378
	return CastTest.class;
2426
	return CastTest.class;
2379
}
2427
}
(-)a/org.eclipse.jdt.core/buildnotes_jdt-core.html (-1 / +3 lines)
Lines 52-58 Link Here
52
<h2>What's new in this drop</h2>
52
<h2>What's new in this drop</h2>
53
53
54
<h3>Problem Reports Fixed</h3>
54
<h3>Problem Reports Fixed</h3>
55
<a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=361441">361441</a>
55
<a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=359284">359284</a>
56
Unnecessary checkast from null
57
<br><a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=361441">361441</a>
56
Error in JDT Core during AST creation
58
Error in JDT Core during AST creation
57
<br><a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=363293">363293</a>
59
<br><a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=363293">363293</a>
58
resource leaks in org.eclipse.jdt.compiler.tool.tests
60
resource leaks in org.eclipse.jdt.compiler.tool.tests
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java (-3 / +2 lines)
Lines 135-143 Link Here
135
			this.initialization.generateCode(currentScope, codeStream, true);
135
			this.initialization.generateCode(currentScope, codeStream, true);
136
			// 26903, need extra cast to store null in array local var
136
			// 26903, need extra cast to store null in array local var
137
			if (this.binding.type.isArrayType()
137
			if (this.binding.type.isArrayType()
138
				&& (this.initialization.resolvedType == TypeBinding.NULL	// arrayLoc = null
138
				&& ((this.initialization instanceof CastExpression)	// arrayLoc = (type[])null
139
					|| ((this.initialization instanceof CastExpression)	// arrayLoc = (type[])null
139
						&& (((CastExpression)this.initialization).innermostCastedExpression().resolvedType == TypeBinding.NULL))){
140
						&& (((CastExpression)this.initialization).innermostCastedExpression().resolvedType == TypeBinding.NULL)))){
141
				codeStream.checkcast(this.binding.type);
140
				codeStream.checkcast(this.binding.type);
142
			}
141
			}
143
			codeStream.store(this.binding, false);
142
			codeStream.store(this.binding, false);
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java (-3 / +2 lines)
Lines 352-360 Link Here
352
			}
352
			}
353
			// 26903, need extra cast to store null in array local var
353
			// 26903, need extra cast to store null in array local var
354
			if (localBinding.type.isArrayType()
354
			if (localBinding.type.isArrayType()
355
				&& (assignment.expression.resolvedType == TypeBinding.NULL	// arrayLoc = null
355
				&& ((assignment.expression instanceof CastExpression)	// arrayLoc = (type[])null
356
					|| ((assignment.expression instanceof CastExpression)	// arrayLoc = (type[])null
356
						&& (((CastExpression)assignment.expression).innermostCastedExpression().resolvedType == TypeBinding.NULL))){
357
						&& (((CastExpression)assignment.expression).innermostCastedExpression().resolvedType == TypeBinding.NULL)))){
358
				codeStream.checkcast(localBinding.type);
357
				codeStream.checkcast(localBinding.type);
359
			}
358
			}
360
359

Return to bug 359284