Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 353495 - NPE in JDTPackage constructor for default packages
Summary: NPE in JDTPackage constructor for default packages
Status: RESOLVED FIXED
Alias: None
Product: Dali JPA Tools
Classification: WebTools
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.0.1   Edit
Assignee: Neil Hauge CLA
QA Contact:
URL:
Whiteboard: fix_ready
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-01 09:28 EDT by Dmitry Geraskov CLA
Modified: 2011-08-02 16:06 EDT (History)
4 users (show)

See Also:
neil.hauge: review+


Attachments
The patch which ignore package-info placed in default package (2.23 KB, patch)
2011-08-02 04:27 EDT, Dmitry Geraskov CLA
karenfbutzke: iplog+
Details | Diff
proposed patch against 3.0 maintenance (4.89 KB, patch)
2011-08-02 14:00 EDT, Karen Butzke CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Geraskov CLA 2011-08-01 09:28:28 EDT
Build Identifier: I20110613-1736

If pacakge-info.java is placed in default package it doesn't have package declaration inside and null is returned. There is no null check in many places for it in my patch provided for https://bugs.eclipse.org/bugs/show_bug.cgi?id=265087 and NPE is thrown.




Reproducible: Always

Steps to Reproduce:
java.lang.NullPointerException
	at org.eclipse.jpt.common.core.internal.utility.jdt.JDTPackage.<init>(JDTPackage.java:44)
	at org.eclipse.jpt.jpa.core.internal.resource.java.source.SourcePackage.newInstance(SourcePackage.java:42)
	at org.eclipse.jpt.jpa.core.internal.resource.java.source.SourcePackageInfoCompilationUnit.buildPackage(SourcePackageInfoCompilationUnit.java:117)
	at org.eclipse.jpt.jpa.core.internal.resource.java.source.SourcePackageInfoCompilationUnit.buildPackage(SourcePackageInfoCompilationUnit.java:90)
	at org.eclipse.jpt.jpa.core.internal.resource.java.source.SourcePackageInfoCompilationUnit.buildPackage(SourcePackageInfoCompilationUnit.java:52)
	at org.eclipse.jpt.jpa.core.internal.resource.java.source.SourcePackageInfoCompilationUnit.<init>(SourcePackageInfoCompilationUnit.java:44)
	at org.jboss.tools.hibernate.jpt.core.internal.JavaPackageInfoResourceModelProviderPatched.buildResourceModel(JavaPackageInfoResourceModelProviderPatched.java:56)
	at org.jboss.tools.hibernate.jpt.core.internal.JavaPackageInfoResourceModelProviderPatched.buildResourceModel(JavaPackageInfoResourceModelProviderPatched.java:1)
	at org.eclipse.jpt.jpa.core.internal.GenericJpaPlatform.buildResourceModel(GenericJpaPlatform.java:111)
	at org.eclipse.jpt.jpa.core.internal.GenericJpaPlatform.buildJpaFile(GenericJpaPlatform.java:105)
Comment 1 Dmitry Geraskov CLA 2011-08-01 09:37:03 EDT
I would like to create a patch for this, but I didn't find or.eclipse.jpt.common.core in the repository :pserver:anonymous@dev.eclipse.org:/cvsroot/webtools.
Could you please help me?
Comment 2 Karen Butzke CLA 2011-08-01 10:11:33 EDT
It's under org.eclipse.jpa/components/common/plugins/
Comment 3 Paul Fullbright CLA 2011-08-01 10:19:57 EDT
Just to be clear, are you attempting to add support for package-info.java in default packages (if so, how can that be done?) or are you merely attempting to provide error handling for the error case of having a package-info.java in a default package?
Comment 4 Dmitry Geraskov CLA 2011-08-02 04:26:23 EDT
There is no problem with having package-info.java in default package from java point of view. The only thing - it is useless as it can't have annotations inside (because of pacakge declaration absence).
JDTPackage throws NPE in constructor when we try to create it for such package-info.java (actually there is no null cheks in many places).

There are 2 ways of fixing this:
1. As package-info.java in default package is useless we can ignore it in JavaPackageInfoResourceModelProvider and return null from buildResourceModel.
2. Add null PacakgeDeclaration checks in JDTPackage (and probably some other classes)

I'll attach a patch with first solution.
If it is suitable for you, please apply, or let me know and I'll create a patch with second solution.
Comment 5 Dmitry Geraskov CLA 2011-08-02 04:27:17 EDT
Created attachment 200690 [details]
The patch which ignore package-info placed in default package

The patch with first solution is attached
Comment 6 Karen Butzke CLA 2011-08-02 14:00:31 EDT
Created attachment 200751 [details]
proposed patch against 3.0 maintenance

I think your solution is reasonable. I've attached a new patch that includes the original change plus the same change in the corresponding JavaPackageInfoResourceModelProvider file in org.eclipse.jpt.jaxb.core
Comment 7 Karen Butzke CLA 2011-08-02 16:06:06 EDT
Checked in to 3_0_maintenance and HEAD. Thanks for the patch!