commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andriy Kharchuk" <andriy.kharc...@gmail.com>
Subject NoSuchMethodException for public method of nonpublic class
Date Thu, 07 Jun 2007 20:04:38 GMT
Hello,

I use library BeanUtils v 1.7.0. NoSuchMethodException is thrown when public
property of non public class is accessed.
This happens because the following check fails in getAccessibleMethod(Method
method) of MethodUtils class:

        // If the declaring class is public, we are done
        Class clazz = method.getDeclaringClass();
        if (Modifier.isPublic(clazz.getModifiers())) {
            return (method);
        }

The code below can be used for tests. Is this the way framework is expected
to work?

public class Main {

    public static void main(String... args) {
        ABean abean = new ABean();
        try {
            System.out.println(PropertyUtils.getSimpleProperty(abean,
"name"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static class ABean {
        private String name;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }
}

Thanks,
Andriy

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message