OpenPojo / openpojo

POJO Testing & Identity Management Made Trivial
http://openpojo.com
Apache License 2.0
156 stars 40 forks source link

Classpath containing spaces results in NPE in PackageHelper.getClasses #8

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a test in a project with spaces in the classpath (ex. E:\My Test 
Project\classes\org\organization\project\package)
2. In your test setup include the line: pojoClasses = 
PojoClassFactory.getPojoClasses( POJO_PACKAGE, new FilterPackageInfo() );
3. In a test, do this:      for( PojoClass pojoClass : pojoClasses )
        {
            pojoValidator.runValidation( pojoClass );
        }

What is the expected output? What do you see instead?
Expect to learn that my tests failed because I'm a lousy programmer. What 
happened instead is I get a NullPointerException resulting from how this line 
of code behaves: File directory = getPackageAsDirectory(packageName);

In my example, directory contains the following: 
"E:\My%20Test%20Project\classes\org\organization\project\package

The immediately following call to directory.listFiles() returns null.

What version of the product are you using? On what operating system?
OpenPojo-build-20100803-1641
Windows XP

Please provide any additional information below.
My test class is a very slightly modified version of your example program. Only 
POJO_PACKAGE has been changed.

Here's the stack trace:

java.lang.NullPointerException
    at com.openpojo.reflection.utils.PackageHelper.getClasses(PackageHelper.java:48)
    at com.openpojo.reflection.impl.PojoPackageImpl.getPojoClasses(PojoPackageImpl.java:49)
    at com.openpojo.reflection.impl.PojoClassFactory.getPojoClasses(PojoClassFactory.java:76)
    at com.blackandwhitesoftware.campscheduler.model.PojoTest.setup(PojoTest.java:45)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Original issue reported on code.google.com by coxfamil...@gmail.com on 28 Aug 2010 at 2:33

GoogleCodeExporter commented 9 years ago
What did you set POJO_PACKAGE to?
Also, what version of the JDK are you using?

I tried a quick test for path with spaces in it and I didn't uncover the error 
you saw, I am not working on windows, so this is going to be my next trial, but 
I wanted to set it up exactly how you have your env.

Thank you,

Osman

Original comment by oshou...@gmail.com on 28 Aug 2010 at 5:25

GoogleCodeExporter commented 9 years ago
found the source of the problem and fixed it... please download new build and 
let me know if you see any other issues.

Original comment by oshou...@gmail.com on 28 Aug 2010 at 6:20

GoogleCodeExporter commented 9 years ago
Osman,

Thanks for the quick turnaround on this. Sorry I wasn't able to get back to you 
sooner, I was out of town and off the grid for a couple of days. To answer your 
questions:

POJO_PACKAGE was set to a standard package String. To borrow from my example 
above it would be "org.organization.project.package".

My JDK is Sun's 1.6.0_20

I'm off to test your fix :)

Original comment by coxfamil...@gmail.com on 30 Aug 2010 at 3:37