diff options
author | M N Palat | 2013-07-05 06:40:12 +0000 |
---|---|---|
committer | M N Palat | 2013-07-05 06:40:12 +0000 |
commit | f47e75c1503f87b47cf6ca8478e948925811cd42 (patch) | |
tree | 83d6a5f43ae7e3a53b72e8f9fbc5fe7a6601e3d2 | |
parent | 4eeaf0d0e03ab922557bc9369f948328bc88b0fc (diff) | |
download | eclipse.jdt.core-f47e75c1503f87b47cf6ca8478e948925811cd42.tar.gz eclipse.jdt.core-f47e75c1503f87b47cf6ca8478e948925811cd42.tar.xz eclipse.jdt.core-f47e75c1503f87b47cf6ca8478e948925811cd42.zip |
Fix for Bug 412155 Calling a @deprecated method in a separate class from
within a lambda causes a ClassCastException and terminates the AST
generation
3 files changed, 66 insertions, 1 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Deprecated18Test.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Deprecated18Test.java new file mode 100644 index 0000000000..40d4cc707e --- /dev/null +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Deprecated18Test.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2013 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +public class Deprecated18Test extends AbstractRegressionTest { +public Deprecated18Test(String name) { + super(name); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); +} +public void test412555() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Runnable r = () -> {\n" + + " Y.callMe();\n" + + " };\n" + + " }\n" + + "}\n", + "Y.java", + "public class Y {\n" + + " @Deprecated\n" + + " public static void callMe() {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Y.callMe();\n" + + " ^^^^^^^^\n" + + "The method callMe() from the type Y is deprecated\n" + + "----------\n", + null, + true, + options); +} +public static Class testClass() { + return Deprecated18Test.class; +} +} diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java index ead3f55d03..a2d15a65dd 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java @@ -136,6 +136,7 @@ public static Test suite() { since_1_8.add(GrammarCoverageTests308.class); since_1_8.add(FlowAnalysisTest8.class); since_1_8.add(TypeAnnotationTest.class); + since_1_8.add(Deprecated18Test.class); // Build final test suite TestSuite all = new TestSuite(TestAll.class.getName()); diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java index 5b93f86d44..b399feb3e1 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java @@ -3234,7 +3234,9 @@ public abstract class Scope { MethodScope methodScope = methodScope(); if (!methodScope.isInsideInitializer()){ // check method modifiers to see if deprecated - MethodBinding context = ((AbstractMethodDeclaration)methodScope.referenceContext).binding; + ReferenceContext referenceContext = methodScope.referenceContext; + MethodBinding context = referenceContext instanceof AbstractMethodDeclaration ? + ((AbstractMethodDeclaration)referenceContext).binding : ((LambdaExpression)referenceContext).binding; if (context != null && context.isViewedAsDeprecated()) return true; } else if (methodScope.initializedField != null && methodScope.initializedField.isViewedAsDeprecated()) { |