https://issues.jboss.org/browse/JBPAPP-7871 #35

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants
Collaborator

liweinan commented Feb 20, 2012

Section 3.3.1 of JAX-RS 1.1. standard:

3.3.1 Visibility Only public methods may be exposed as resource methods. An implementation SHOULD warn users if a non-public method carries a method designator or @path annotation.
https://issues.jboss.org/browse/JBPAPP-7871
Section 3.3.1 of JAX-RS 1.1. standard:

<cite>
3.3.1 Visibility
Only public methods may be exposed as resource methods. An implementation SHOULD warn users if a non-public method carries a method designator or @Path annotation.
</cite>
Collaborator

patriot1burke commented Feb 28, 2012

A better approach is just to check the visibility of the method via a simple reflection call instead of looking up the method

Collaborator

liweinan commented Mar 7, 2012

Thank you for your advice Bill :-) I'll work on this one after I've finished my work at hand.

Collaborator

liweinan commented Mar 15, 2012

Hi Bill, I've tried to use reflection to check method's reflection and seems it doesn't work:

public class Foo {

    private static class Bar {
        public void method1() {}
        private void method2() {}
        public static void method3() {}
    }
    public static void main(String[] args) throws NoSuchMethodException {
        System.out.println(Bar.class.getMethod("method1", null).isAccessible());
        System.out.println(Bar.class.getDeclaredMethod("method2", null).isAccessible());
        System.out.println(Bar.class.getDeclaredMethod("method3", null).isAccessible());
    }
}

Here is the output:

false
false
false

From the explanation in javadoc:

isAccessible() 
          Get the value of the accessible flag for this object.

Seem it just check the accessible flag no matter the method is public or not. Unless we setAccessible(true) it will always return false.

Maybe you are referring on alternative ways to check the non-public methods that I don't know. Could you please help on this one?

Collaborator

patriot1burke commented Mar 29, 2012

Use

java.lang.reflect.Modifer.isPublic(method.getModifiers()))

This is basic Java. Please do a little more research next time. Also, you need to patch 2.3 as well, i'll send you how to do that.

Collaborator

liweinan commented Mar 30, 2012

Thank you for help Bill :-) Next time I'll do more researches on the APIs I haven't used before.

@liweinan liweinan closed this Mar 30, 2012

@liweinan liweinan deleted the liweinan:JBPAPP-7871-revised branch Jul 23, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment