/* * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * 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. */ /* * @test * @bug 8054213 * @summary Check that toString method works properly for generic return type * obtained via reflection * @run main TestGenericReturnTypeToString */ import java.util.List; public class TestGenericReturnTypeToString { private static final String FOO1_EXPECTED_RESULT = "TestGenericReturnTypeToString$" + "FirstInnerClassGeneric$SecondInnerClassGeneric"; private static final String FOO2_EXPECTED_RESULT = "TestGenericReturnTypeToString$" + "FirstInnerClassGeneric$SecondInnerClass"; private static final String FOO3_EXPECTED_RESULT = "TestGenericReturnTypeToString$" + "FirstInnerClass$SecondInnerClassGeneric"; private static final String FOO4_EXPECTED_RESULT = "class " + "TestGenericReturnTypeToString$FirstInnerClass$SecondInnerClass"; private static final String FOO5_EXPECTED_RESULT = "java.util.List"; public static void main(String[] args) throws NoSuchMethodException { test("foo1", FOO1_EXPECTED_RESULT); test("foo2", FOO2_EXPECTED_RESULT); test("foo3", FOO3_EXPECTED_RESULT); test("foo4", FOO4_EXPECTED_RESULT); test("foo5", FOO5_EXPECTED_RESULT); } private static void test(String methodName, String expectedResult) throws NoSuchMethodException { if (!TestGenericReturnTypeToString.class.getMethod(methodName). getGenericReturnType().toString().equals(expectedResult)) { throw new RuntimeException("Expected " + expectedResult + ", Actual: " + TestGenericReturnTypeToString.class .getMethod(methodName).getGenericReturnType()); } } public FirstInnerClassGeneric.SecondInnerClassGeneric foo1() { return null; } public FirstInnerClassGeneric.SecondInnerClass foo2() { return null; } public FirstInnerClass.SecondInnerClassGeneric foo3() { return null; } public FirstInnerClass.SecondInnerClass foo4() { return null; } public List foo5() { return null; } public class FirstInnerClass { public class SecondInnerClassGeneric { } public class SecondInnerClass { } } public class FirstInnerClassGeneric { public class SecondInnerClassGeneric { } public class SecondInnerClass { } } } class Dummy { }