Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 353495

Summary: NPE in JDTPackage constructor for default packages
Product: [WebTools] Dali JPA Tools Reporter: Dmitry Geraskov <geraskov>
Component: GeneralAssignee: Neil Hauge <neil.hauge>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3 CC: geraskov, karenfbutzke, neil.hauge, paul.fullbright
Version: unspecifiedFlags: neil.hauge: review+
Target Milestone: 3.0.1   
Hardware: PC   
OS: Windows XP   
Whiteboard: fix_ready
Attachments:
Description Flags
The patch which ignore package-info placed in default package
karenfbutzke: iplog+
proposed patch against 3.0 maintenance none

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!