/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
/*
7157574 method handles returned by reflective lookup API sometimes have wrong receiver type
When an inherited non-static field or method is looked up in a class C using Lookup.findVirtual(C...), etc., the JSR 292 API, the first argument of the resulting method handle must be the receiver ('this'), and must be the requested class (or more specific, in the case of findSpecial or a lookup of a protected method).
But currently, if a supertype T defines the looked-up method or field and C inherits it, the returned method handle might have the more specific initial type T.
The relevant javadoc (and 292 spec.) is as follows:
* The formal parameter {@code this} stands for the self-reference of type {@code C};
* if it is present, it is always the leading argument to the method handle invocation.
* (In the case of some {@code protected} members, {@code this} may be
* restricted in type to the lookup class; see below.)
Because of this bug, all of the assertions fail in the following example:
*/
/* @test
* @bug 7157574
* @summary method handles returned by reflective lookup API sometimes have wrong receiver type
*
* @run main Test7157574
*/
public class Test7157574 {
// test the MHs on a concrete version of Sub
class C extends Sub {
// Pack the vtable of Intf with leading junk:
private void ig() { throw new RuntimeException(); }
}
}
) throws Throwable {
s.f2 = 0;
m1.invokeExact(s);
m2.invokeExact(s);
s.f2 = 2;
}
throw new AssertionError(msg);
}
}