From 79bc5790292b41e43b01dff30ef83be81fa78b14 Mon Sep 17 00:00:00 2001 From: Abhijit Kulkarni Date: Sun, 26 Nov 2023 00:16:39 -0800 Subject: [PATCH] cleaning up unnecessary condition and adding a comment --- .../generics/PreservedAnnotationTreeVisitor.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/nullaway/src/main/java/com/uber/nullaway/generics/PreservedAnnotationTreeVisitor.java b/nullaway/src/main/java/com/uber/nullaway/generics/PreservedAnnotationTreeVisitor.java index dfb3fe6774..aabc35ee67 100644 --- a/nullaway/src/main/java/com/uber/nullaway/generics/PreservedAnnotationTreeVisitor.java +++ b/nullaway/src/main/java/com/uber/nullaway/generics/PreservedAnnotationTreeVisitor.java @@ -170,15 +170,11 @@ public TypeMetadata create(com.sun.tools.javac.util.List @Override public Type cloneTypeWithMetaData(Type typeToBeCloned, TypeMetadata metaData) { try { - Type clonedType = null; - if (metaData.getClass().getComponentType() != null) { - clonedType = (Type) cloneAddMetadataHandle.invoke(typeToBeCloned, metaData); - } else { - Type clonedTypeDrop = - (Type) cloneDropMetadataHandle.invoke(typeToBeCloned, metaData.getClass()); - clonedType = (Type) cloneAddMetadataHandle.invoke(clonedTypeDrop, metaData); - } - return clonedType; + // In Jdk21 addMetadata works if there is no metadata associated with the type, so we create + // a copy without the existing metadata first and then add it + Type clonedTypeWithoutMetadata = + (Type) cloneDropMetadataHandle.invoke(typeToBeCloned, metaData.getClass()); + return (Type) cloneAddMetadataHandle.invoke(clonedTypeWithoutMetadata, metaData); } catch (Throwable e) { throw new RuntimeException(e); }