gidoUninova / jenabean

Automatically exported from code.google.com/p/jenabean
1 stars 4 forks source link

NullPointerException hides true cause #3

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Follow the tutorial on the QuickStartReadingRDF wiki page
(http://code.google.com/p/jenabean/wiki/QuickStartReadingRDF) in a
haphazard manner, and leave the Bean in the default package.

What is the expected output? What do you see instead?

I get the following exception trace:

Exception in thread "main" java.lang.NullPointerException
    at thewebsemantic.TypeWrapper.<init>(TypeWrapper.java:46)
    at thewebsemantic.TypeWrapper.wrap(TypeWrapper.java:68)
    at thewebsemantic.RDF2Bean.newInstance(RDF2Bean.java:437)
    at thewebsemantic.RDF2Bean.applyProperties(RDF2Bean.java:425)
    at thewebsemantic.RDF2Bean.testCycle(RDF2Bean.java:394)
    at thewebsemantic.RDF2Bean.toObject(RDF2Bean.java:390)
    at thewebsemantic.RDF2Bean.loadIndividuals(RDF2Bean.java:162)
    at thewebsemantic.RDF2Bean.loadAll(RDF2Bean.java:155)
    at thewebsemantic.RDF2Bean.load(RDF2Bean.java:140)
    at thewebsemantic.RDF2Bean.load(RDF2Bean.java:106)
    at thewebsemantic.binding.Jenabean.load(Jenabean.java:101)
    at Test.main(Test.java:38)

The problem appears to be due to the use of Class.getPackage() in the
TypeWrapper constructor. getPackage() returns null when the class has no
package.

    private <T> TypeWrapper(Class<T> c) {
        ...
        Namespace nsa = c.getAnnotation(Namespace.class);
        NS = (nsa != null) ? nsa.value() : "http://"
                + c.getPackage().getName() + '/';

No doubt adding a package name to my bean will resolve the problem, but it
took me a while to understand the exact problem. Checking the return value
of getPackage and either throwing a more helpful exception, or working
round the lack of package would be helpful.

What version of the product are you using? On what operating system?

Jenabean 0.0.4 on Windows Vista.

Original issue reported on code.google.com by matburn...@gmail.com on 29 Mar 2008 at 3:37

GoogleCodeExporter commented 9 years ago
Hi Matt, thanks for letting us know...haven't used default package in a long 
time. 
Fixed the bug and checked in test cases.

Original comment by thewebse...@gmail.com on 6 Nov 2008 at 5:06