Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/trigger_files/beam_PostCommit_Java_DataflowV1.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"https://github.com/apache/beam/pull/36138": "Cleanly separating v1 worker and v2 sdk harness container image handling",
"https://github.com/apache/beam/pull/39330": "Fix DataflowV1 test failure by fixing getSimpleName access",
"https://github.com/apache/beam/pull/34902": "Introducing OutputBuilder",
"https://github.com/apache/beam/pull/35177": "Introducing WindowedValueReceiver to runners",
"comment": "Modify this file in a trivial way to cause this test suite to run",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Set;
import org.apache.beam.sdk.options.ValueProvider;
import org.apache.beam.sdk.transforms.PTransform;
import org.apache.beam.sdk.util.common.ReflectHelpers;
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Joiner;
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableList;
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -617,7 +618,7 @@ FormattedItemValue format(Object value) {
@Override
FormattedItemValue format(Object value) {
Class<?> clazz = checkType(value, Class.class, JAVA_CLASS);
return new FormattedItemValue(clazz.getName(), clazz.getSimpleName());
return new FormattedItemValue(clazz.getName(), ReflectHelpers.getSimpleName(clazz));
}
};

Expand Down Expand Up @@ -753,10 +754,10 @@ private Builder include(Path path, HasDisplayData subComponent) {
// Common case: AutoValue classes such as AutoValue_FooIO_Read. It's more useful
// to show the user the FooIO.Read class, which is the direct superclass of the AutoValue
// generated class.
if (namespace.getSimpleName().startsWith("AutoValue_")) {
if (ReflectHelpers.getSimpleName(namespace).startsWith("AutoValue_")) {
namespace = namespace.getSuperclass();
}
if (namespace.isSynthetic() && namespace.getSimpleName().contains("$$Lambda")) {
if (namespace.isSynthetic() && ReflectHelpers.getSimpleName(namespace).contains("$$Lambda")) {
try {
String className = namespace.getCanonicalName();
// A local class, local interface, or anonymous class does not have a canonical name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2421,7 +2421,8 @@ private static String format(TypeDescriptor<?> t) {
}

private static String format(Class<?> kls) {
return kls.getSimpleName().isEmpty() ? kls.getName() : kls.getSimpleName();
String simpleName = ReflectHelpers.getSimpleName(kls);
return simpleName.isEmpty() ? kls.getName() : simpleName;
}

static class ErrorReporter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,29 @@ public class ReflectHelpers {

private static final Joiner COMMA_SEPARATOR = Joiner.on(", ");

/**
* Returns the simple name of the given class, or a fallback simple name derived from the class
* name if {@link Class#getSimpleName()} throws an exception (such as an {@link
* IllegalAccessError} on Java 17+ for non-public inner classes).
*/
public static String getSimpleName(Class<?> clazz) {
try {
return clazz.getSimpleName();
} catch (Throwable t) {
if (clazz.isArray()) {
return getSimpleName(clazz.getComponentType()) + "[]";
}
String name = clazz.getName();
int idx = Math.max(name.lastIndexOf('.'), name.lastIndexOf('$'));
return idx != -1 ? name.substring(idx + 1) : name;
}
}
Comment thread
Abacn marked this conversation as resolved.

/** Returns a string representation of the signature of a {@link Method}. */
public static String formatMethod(Method input) {
String parameterTypes =
FluentIterable.from(asList(input.getParameterTypes()))
.transform(Class::getSimpleName)
.transform(ReflectHelpers::getSimpleName)
.join(COMMA_SEPARATOR);
return String.format("%s(%s)", input.getName(), parameterTypes);
}
Expand Down Expand Up @@ -100,7 +118,7 @@ private static void format(StringBuilder builder, Type t) {
}

private static void formatClass(StringBuilder builder, Class<?> clazz) {
builder.append(clazz.getSimpleName());
builder.append(getSimpleName(clazz));
}

private static void formatTypeVariable(StringBuilder builder, TypeVariable<?> t) {
Expand Down
Loading