From d625680a2a8daf6e99f799c780ea91cb411795ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Schn=C3=A9ider?= Date: Wed, 13 Nov 2024 14:59:42 -0600 Subject: [PATCH] Fix condition where Attribute#getValue() throws an unsupported operation exception (#4669) --- .../java/isolated/ReloadableJava11TypeMapping.java | 6 +++++- .../java/isolated/ReloadableJava17TypeMapping.java | 6 +++++- .../java/isolated/ReloadableJava21TypeMapping.java | 6 +++++- .../org/openrewrite/java/ReloadableJava8TypeMapping.java | 6 +++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/rewrite-java-11/src/main/java/org/openrewrite/java/isolated/ReloadableJava11TypeMapping.java b/rewrite-java-11/src/main/java/org/openrewrite/java/isolated/ReloadableJava11TypeMapping.java index 5f3295c40a7..d0b90bea744 100644 --- a/rewrite-java-11/src/main/java/org/openrewrite/java/isolated/ReloadableJava11TypeMapping.java +++ b/rewrite-java-11/src/main/java/org/openrewrite/java/isolated/ReloadableJava11TypeMapping.java @@ -579,7 +579,11 @@ public JavaType.Primitive primitive(TypeTag tag) { .map(attr -> attr.getValue().toString()) .collect(Collectors.toList()); } else { - defaultValues = Collections.singletonList(methodSymbol.getDefaultValue().getValue().toString()); + try { + defaultValues = Collections.singletonList(methodSymbol.getDefaultValue().getValue().toString()); + } catch(UnsupportedOperationException e) { + // not all Attribute implementations define `getValue()` + } } } JavaType.Method method = new JavaType.Method( diff --git a/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17TypeMapping.java b/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17TypeMapping.java index b7c7ff483ff..7d5ad9da3f6 100644 --- a/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17TypeMapping.java +++ b/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17TypeMapping.java @@ -588,7 +588,11 @@ public JavaType.Primitive primitive(TypeTag tag) { .map(attr -> attr.getValue().toString()) .collect(Collectors.toList()); } else { - defaultValues = Collections.singletonList(methodSymbol.getDefaultValue().getValue().toString()); + try { + defaultValues = Collections.singletonList(methodSymbol.getDefaultValue().getValue().toString()); + } catch(UnsupportedOperationException e) { + // not all Attribute implementations define `getValue()` + } } } JavaType.Method method = new JavaType.Method( diff --git a/rewrite-java-21/src/main/java/org/openrewrite/java/isolated/ReloadableJava21TypeMapping.java b/rewrite-java-21/src/main/java/org/openrewrite/java/isolated/ReloadableJava21TypeMapping.java index f55a32132b8..10d9b202c6f 100644 --- a/rewrite-java-21/src/main/java/org/openrewrite/java/isolated/ReloadableJava21TypeMapping.java +++ b/rewrite-java-21/src/main/java/org/openrewrite/java/isolated/ReloadableJava21TypeMapping.java @@ -599,7 +599,11 @@ public JavaType.Primitive primitive(TypeTag tag) { .map(attr -> attr.getValue().toString()) .collect(Collectors.toList()); } else { - defaultValues = Collections.singletonList(methodSymbol.getDefaultValue().getValue().toString()); + try { + defaultValues = Collections.singletonList(methodSymbol.getDefaultValue().getValue().toString()); + } catch(UnsupportedOperationException e) { + // not all Attribute implementations define `getValue()` + } } } JavaType.Method method = new JavaType.Method( diff --git a/rewrite-java-8/src/main/java/org/openrewrite/java/ReloadableJava8TypeMapping.java b/rewrite-java-8/src/main/java/org/openrewrite/java/ReloadableJava8TypeMapping.java index 0d8408dd026..988b0920206 100644 --- a/rewrite-java-8/src/main/java/org/openrewrite/java/ReloadableJava8TypeMapping.java +++ b/rewrite-java-8/src/main/java/org/openrewrite/java/ReloadableJava8TypeMapping.java @@ -581,7 +581,11 @@ public JavaType.Primitive primitive(TypeTag tag) { .map(attr -> attr.getValue().toString()) .collect(Collectors.toList()); } else { - defaultValues = Collections.singletonList(methodSymbol.getDefaultValue().getValue().toString()); + try { + defaultValues = Collections.singletonList(methodSymbol.getDefaultValue().getValue().toString()); + } catch(UnsupportedOperationException e) { + // not all Attribute implementations define `getValue()` + } } } JavaType.Method method = new JavaType.Method(