I file an issue DERBY- 5041 https://issues.apache.org/jira/browse/DERBY-5041 on your behave. If there is any addition information, please feel free to add it. Like Dag's point out, complex query like this often result from code generation error from some bug during binding time and/or optimization time. A real life reproducible case will help a lot to debug case like this. And, shorten the time to get the bug fixed from Derby-dev.
Thanks and hope this help,
|From:||Kathey Marsden <firstname.lastname@example.org>|
|To:||Derby Discussion <email@example.com>|
|Cc:||Pavel Bortnovskiy <PBortnovskiy@Jefferies.com>|
|Date:||02/09/2011 01:54 PM|
|Subject:||Re: NullPointerException deep in Derby|