8021398: j.l.r.Parameter.getAnnotatedType().getType() for not annotated use of type returns null

Fixed issue with type annotation reflection framework that would cause getType of AnnotatedTypes to be null if no annotations were present.

Reviewed-by: darcy, jfranck
This commit is contained in:
Eric McCorkle 2013-10-01 17:35:32 -04:00
parent 8e924e70a6
commit e92da66e0b
2 changed files with 49 additions and 6 deletions

View File

@ -128,14 +128,18 @@ public class TypeAnnotationParser {
for (int i = 0; i < size; i++) {
@SuppressWarnings("unchecked")
ArrayList<TypeAnnotation> list = l[i];
TypeAnnotation[] typeAnnotations;
if (list != null) {
TypeAnnotation[] typeAnnotations = list.toArray(new TypeAnnotation[0]);
result[i] = AnnotatedTypeFactory.buildAnnotatedType(types[i],
LocationInfo.BASE_LOCATION,
typeAnnotations,
typeAnnotations,
decl);
typeAnnotations = list.toArray(new TypeAnnotation[list.size()]);
} else {
typeAnnotations = EMPTY_TYPE_ANNOTATION_ARRAY;
}
result[i] = AnnotatedTypeFactory.buildAnnotatedType(types[i],
LocationInfo.BASE_LOCATION,
typeAnnotations,
typeAnnotations,
decl);
}
return result;
}

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2013, 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.
*
* 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
* @compile -parameters GetAnnotatedTypeTest.java
* @run main GetAnnotatedTypeTest
* @summary javac should generate method parameters correctly.
*/
public class GetAnnotatedTypeTest {
public void meth(Object param) {}
public static void main(String[] args) throws NoSuchMethodException {
if (GetAnnotatedTypeTest.class.getMethod("meth", Object.class).getParameters()[0].getAnnotatedType().getType() != Object.class)
throw new RuntimeException("Parameter did not have the expected annotated type");
}
}