Skip to content

Commit

Permalink
Retain parameter name for records to mimic OpenJDK behaviour.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Jul 22, 2021
1 parent d67c7f3 commit da712db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion byte-buddy-dep/src/main/java/net/bytebuddy/ByteBuddy.java
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,9 @@ public List<MethodDescription.Token> extractConstructors(TypeDescription instrum
List<ParameterDescription.Token> tokens = new ArrayList<ParameterDescription.Token>(instrumentedType.getRecordComponents().size());
for (RecordComponentDescription.InDefinedShape recordComponent : instrumentedType.getRecordComponents()) {
tokens.add(new ParameterDescription.Token(recordComponent.getType(),
recordComponent.getDeclaredAnnotations().filter(targetsElement(ElementType.CONSTRUCTOR))));
recordComponent.getDeclaredAnnotations().filter(targetsElement(ElementType.CONSTRUCTOR)),
recordComponent.getActualName(),
ModifierContributor.EMPTY_MASK));
}
return Collections.singletonList(new MethodDescription.Token(MethodDescription.CONSTRUCTOR_INTERNAL_NAME,
Opcodes.ACC_PUBLIC,
Expand Down
5 changes: 5 additions & 0 deletions byte-buddy-dep/src/test/java/net/bytebuddy/ByteBuddyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.junit.Rule;
import org.junit.Test;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.URL;
Expand Down Expand Up @@ -108,6 +109,10 @@ public void testRecordWithMember() throws Exception {
assertThat(type.getMethod("equals", Object.class).invoke(record, new Object()), is((Object) false));
assertThat(type.getMethod("equals", Object.class).invoke(record, record), is((Object) true));
assertThat(type.getMethod("toString").invoke(record), is((Object) (type.getSimpleName() + "[foo=bar]")));
Object[] parameter = (Object[]) Constructor.class.getMethod("getParameters").invoke(type.getDeclaredConstructor(String.class));
assertThat(parameter.length, is(1));
assertThat(Class.forName("java.lang.reflect.Parameter").getMethod("getName").invoke(parameter[0]), is((Object) "foo"));
assertThat(Class.forName("java.lang.reflect.Parameter").getMethod("getModifiers").invoke(parameter[0]), is((Object) 0));
}

@Test
Expand Down

0 comments on commit da712db

Please sign in to comment.