8379156: Specify behavior of Types.asElement() on array types

Reviewed-by: hannesw, liach
This commit is contained in:
Joe Darcy 2026-03-06 17:20:44 +00:00
parent 0aa52d633a
commit ea4a151245
2 changed files with 12 additions and 6 deletions

View File

@ -74,6 +74,7 @@ public interface Types {
* Types <em>without</em> corresponding elements include:
* <ul>
* <li>{@linkplain TypeKind#isPrimitive() primitive types}
* <li>{@linkplain TypeKind#ARRAY array types}
* <li>{@linkplain TypeKind#EXECUTABLE executable types}
* <li>{@linkplain TypeKind#NONE "none"} pseudo-types
* <li>{@linkplain TypeKind#NULL null types}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2026, 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
@ -23,7 +23,7 @@
/*
* @test
* @bug 8300857
* @bug 8300857 8379156
* @summary Test Types.asElement in cases specified to return null
* @library /tools/javac/lib
* @build JavacTestingAbstractProcessor TestAsElement
@ -55,18 +55,23 @@ public class TestAsElement extends JavacTestingAbstractProcessor {
}
private void testNullCases() {
// Test all primitive types
// Test all primitive types and arrays of primitive types
for (TypeKind typeKind : TypeKind.values()) {
if (typeKind.isPrimitive() ) {
expectNullAsElement(typeUtils.getPrimitiveType(typeKind));
var primType = typeUtils.getPrimitiveType(typeKind);
expectNullAsElement(primType);
expectNullAsElement(typeUtils.getArrayType(primType));
}
}
expectNullAsElement(typeUtils.getNoType(TypeKind.VOID));
expectNullAsElement(typeUtils.getNoType(TypeKind.NONE));
expectNullAsElement(typeUtils.getNullType());
Element objectElement = eltUtils.getTypeElement("java.lang.Object");
expectNullAsElement(typeUtils.getWildcardType(objectElement.asType(), null));
Element objectElement = eltUtils.getTypeElement("java.lang.Object");
TypeMirror objectType = objectElement.asType();
expectNullAsElement(typeUtils.getWildcardType(objectType, null));
// check Object[]
expectNullAsElement(typeUtils.getArrayType(objectType));
// Loop over the ExecutableTypes for Object's methods
for(var methodElt : ElementFilter.methodsIn(objectElement.getEnclosedElements())) {