Skip to content

Commit

Permalink
Adjust modifier resolution for native methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Dec 13, 2023
1 parent 1bce7c0 commit 5c0c438
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,14 @@ public int getActualModifiers() {
* {@inheritDoc}
*/
public int getActualModifiers(boolean manifest) {
return manifest
? getActualModifiers() & ~(Opcodes.ACC_ABSTRACT | Opcodes.ACC_NATIVE)
: getActualModifiers() & ~Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT;
int modifiers = getActualModifiers();
if (manifest) {
return modifiers & ~(Opcodes.ACC_ABSTRACT | Opcodes.ACC_NATIVE);
} else if ((modifiers & (Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT)) == 0) {
return modifiers | Opcodes.ACC_ABSTRACT;
} else {
return modifiers;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public abstract class AbstractMethodDescriptionTest {
@Rule
public MethodRule javaVersionRule = new JavaVersionRule();

protected Method firstMethod, secondMethod, thirdMethod, genericMethod, genericMethodWithRawException, genericMethodWithTypeVariable;
protected Method firstMethod, secondMethod, thirdMethod, genericMethod, genericMethodWithRawException, genericMethodWithTypeVariable, nativeMethod;

protected Constructor<?> firstConstructor, secondConstructor;

Expand Down Expand Up @@ -72,6 +72,7 @@ public void setUp() throws Exception {
genericMethod = GenericMethod.class.getDeclaredMethod("foo", Exception.class);
genericMethodWithRawException = GenericMethod.class.getDeclaredMethod("bar", Exception.class);
genericMethodWithTypeVariable = GenericMethod.class.getDeclaredMethod("qux");
nativeMethod = NativeMethod.class.getDeclaredMethod("foo");
}

@Test
Expand Down Expand Up @@ -735,6 +736,8 @@ public void testGetActualModifiers() throws Exception {
assertThat(describe(DeprecationSample.class.getDeclaredMethod("foo")).getActualModifiers(), is(Opcodes.ACC_PRIVATE | Opcodes.ACC_DEPRECATED));
assertThat(describe(firstMethod).getActualModifiers(true, Visibility.PUBLIC), is(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC));
assertThat(describe(secondMethod).getActualModifiers(false, Visibility.PRIVATE), is(Opcodes.ACC_PROTECTED | Opcodes.ACC_ABSTRACT));
assertThat(describe(nativeMethod).getActualModifiers(false, Visibility.PRIVATE), is(Opcodes.ACC_NATIVE));
assertThat(describe(nativeMethod).getActualModifiers(true, Visibility.PRIVATE), is(0));
}

@Test
Expand Down Expand Up @@ -960,6 +963,11 @@ <Q> void qux() {
}
}

static class NativeMethod {

native void foo();
}

private static class DeprecationSample {

@Deprecated
Expand Down

0 comments on commit 5c0c438

Please sign in to comment.