Bug 242933 - [1.5] NullPointerException for @Range(min=1, max=9999999999999999)
Summary: [1.5] NullPointerException for @Range(min=1, max=9999999999999999)
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4.1   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 245942 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-08-01 18:00 EDT by Missing name CLA
Modified: 2016-02-05 10:26 EST (History)
4 users (show)

See Also:
philippe_mulet: pmc_approved+


Attachments
Proposed fix (983 bytes, patch)
2008-08-06 22:16 EDT, Olivier Thomann CLA
no flags Details | Diff
Regression test (2.08 KB, patch)
2008-08-06 22:17 EDT, Olivier Thomann CLA
no flags Details | Diff
Same fix and test for R3_4_maintenance (2.78 KB, patch)
2008-09-03 06:50 EDT, Jerome Lanneluc CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Missing name CLA 2008-08-01 18:00:00 EDT
Build ID: I20080617-2000

Steps To Reproduce:
1.
Copy && paste the following code:

package net.cellbell.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.validator.Range;

@Entity
@Table(name = "CB_BSENDER_CH")
@org.hibernate.annotations.Entity(dynamicUpdate=true, dynamicInsert=true)
public class CbBsenderCh
{
	                            // PK    Type       NULL?    DEFAULT VAL.
	private int    id;          // 1/1   NUMBER(9)  n        -
	private int    channel;
	private Date   entTime;
	private Date   until;
	private String addr;
	private String reasonDesc;
	
	public CbBsenderCh()
	{
		// Intentionally empty.
	}

	@Id
	@Column(unique = true, nullable = false, precision = 18, scale = 0)
	//@GeneratedValue(strategy = GenerationType.AUTO, generator = "zdefinitions_seq")
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "cb_bsender_ch_generator")
	@SequenceGenerator(name = "cb_bsender_ch_generator", sequenceName = "CB_BSENDER_CH_SEQ", allocationSize=1)
	@Range(min=1, max=9999999999999999)
	public long getId()
	{
		return id;
	}

	void setId(final long id)
	{
		this.id = id;
	}
}


2.
Then you will get a following Exception:

java.lang.NullPointerException
	at org.eclipse.jdt.internal.core.util.Util.getAnnotationMemberValue(Util.java:3003)
	at org.eclipse.jdt.internal.core.CompilationUnitStructureRequestor.getMemberValue(CompilationUnitStructureRequestor.java:650)
	at org.eclipse.jdt.internal.core.CompilationUnitStructureRequestor.getMemberValuePair(CompilationUnitStructureRequestor.java:631)
	at org.eclipse.jdt.internal.core.CompilationUnitStructureRequestor.getMemberValuePairs(CompilationUnitStructureRequestor.java:638)
	at org.eclipse.jdt.internal.core.CompilationUnitStructureRequestor.enterAnnotation(CompilationUnitStructureRequestor.java:272)
	at org.eclipse.jdt.internal.core.CompilationUnitStructureRequestor.enterMethod(CompilationUnitStructureRequestor.java:438)
	at org.eclipse.jdt.internal.compiler.SourceElementNotifier.notifySourceElementRequestor(SourceElementNotifier.java:347)
	at org.eclipse.jdt.internal.compiler.SourceElementNotifier.notifySourceElementRequestor(SourceElementNotifier.java:665)
	at org.eclipse.jdt.internal.compiler.SourceElementNotifier.notifySourceElementRequestor(SourceElementNotifier.java:431)
	at org.eclipse.jdt.internal.compiler.SourceElementParser.parseCompilationUnit(SourceElementParser.java:912)
	at org.eclipse.jdt.internal.core.CompilationUnit.buildStructure(CompilationUnit.java:196)
	at org.eclipse.jdt.internal.core.Openable.generateInfos(Openable.java:257)
	at org.eclipse.jdt.internal.core.JavaElement.openWhenClosed(JavaElement.java:514)
	at org.eclipse.jdt.internal.core.BecomeWorkingCopyOperation.executeOperation(BecomeWorkingCopyOperation.java:38)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:709)
	at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:770)
	at org.eclipse.jdt.internal.core.CompilationUnit.becomeWorkingCopy(CompilationUnit.java:100)
	at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitDocumentProvider.createFileInfo(CompilationUnitDocumentProvider.java:982)
	at org.eclipse.ui.editors.text.TextFileDocumentProvider.connect(TextFileDocumentProvider.java:476)
	at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitDocumentProvider.connect(CompilationUnitDocumentProvider.java:1197)
	at org.eclipse.ui.texteditor.AbstractTextEditor.doSetInput(AbstractTextEditor.java:3990)
	at org.eclipse.ui.texteditor.StatusTextEditor.doSetInput(StatusTextEditor.java:190)
	at org.eclipse.ui.texteditor.AbstractDecoratedTextEditor.doSetInput(AbstractDecoratedTextEditor.java:1325)
	at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.internalDoSetInput(JavaEditor.java:2512)
	at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.doSetInput(JavaEditor.java:2485)
	at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor.doSetInput(CompilationUnitEditor.java:1350)
	at org.eclipse.ui.texteditor.AbstractTextEditor$19.run(AbstractTextEditor.java:3025)
	at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:446)
	at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:354)
	at org.eclipse.jface.window.ApplicationWindow$1.run(ApplicationWindow.java:758)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
	at org.eclipse.jface.window.ApplicationWindow.run(ApplicationWindow.java:755)
	at org.eclipse.ui.internal.WorkbenchWindow.run(WorkbenchWindow.java:2483)
	at org.eclipse.ui.texteditor.AbstractTextEditor.internalInit(AbstractTextEditor.java:3043)
	at org.eclipse.ui.texteditor.AbstractTextEditor.init(AbstractTextEditor.java:3070)
	at org.eclipse.ui.internal.EditorManager.createSite(EditorManager.java:799)
	at org.eclipse.ui.internal.EditorReference.createPartHelper(EditorReference.java:643)
	at org.eclipse.ui.internal.EditorReference.createPart(EditorReference.java:428)
	at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:594)
	at org.eclipse.ui.internal.EditorAreaHelper.setVisibleEditor(EditorAreaHelper.java:263)
	at org.eclipse.ui.internal.EditorManager.setVisibleEditor(EditorManager.java:1410)
	at org.eclipse.ui.internal.EditorManager$5.runWithException(EditorManager.java:944)
	at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:133)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3800)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3425)
	at org.eclipse.ui.application.WorkbenchAdvisor.openWindows(WorkbenchAdvisor.java:803)
	at org.eclipse.ui.internal.Workbench$27.runWithException(Workbench.java:1361)
	at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:133)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3800)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3425)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2293)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2198)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:493)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:488)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:382)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	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.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1236)

3.
The victim is a line:
@Range(min=1, max=9999999999999999)

Regards,
Adam

More information:
Comment 1 Olivier Thomann CLA 2008-08-05 18:25:45 EDT
I will investigate.
Comment 2 Missing name CLA 2008-08-05 18:36:54 EDT
Hello Olivier

Additional comment:
Here you have a Javadoc to this Range annotation:
http://www.hibernate.org/hib_docs/validator/api/org/hibernate/validator/Range.html

As you can see, Range annotation expecting long parameters but I entered 9999999999999999 (without "L" on the end) and this value is greater than MAX_INTEGER.
Regards,
Adam (Poland)
Comment 3 Olivier Thomann CLA 2008-08-06 21:48:52 EDT
Reproduced.
I think in this case the best we can do is to report null as the value of the corresponding member value pair. When the constant is computed, it fails as an int and therefore the constant field is still null.
Comment 4 Olivier Thomann CLA 2008-08-06 22:16:33 EDT
Created attachment 109363 [details]
Proposed fix
Comment 5 Olivier Thomann CLA 2008-08-06 22:17:09 EDT
Created attachment 109364 [details]
Regression test
Comment 6 Olivier Thomann CLA 2008-08-06 22:17:51 EDT
Jérôme,

Please review.
Comment 7 Jerome Lanneluc CLA 2008-08-20 07:58:44 EDT
Patch is good. Fix and test released for 3.5M2
Comment 8 Jerome Lanneluc CLA 2008-09-02 11:56:33 EDT
*** Bug 245942 has been marked as a duplicate of this bug. ***
Comment 9 Jerome Lanneluc CLA 2008-09-03 05:57:34 EDT
Steps from commenbt 0 won't reproduce since hibernate is assumed.
To reproduce:
1. Start empty workspace on 1.5 JDK
2. Paste the following in Package Explorer:
public class X {
	private int id;
	@Range(max=9999999999999999)
	public long getId() {
		return id;
	}
}
@interface Range {
	long min() default -9223372036854775808L;
	long max() default 9223372036854775807L;
	String message() default "";
}
Observe: You get a dialog with the NullPointerException
Comment 10 Jerome Lanneluc CLA 2008-09-03 06:02:44 EDT
This is a regression comparing to 3.3.x (you don't get the NPE when opening a Java editor with the given source). 

Asking PMC approval to backport to 3.4.1 since the fix is also trivial.
Comment 11 Philipe Mulet CLA 2008-09-03 06:07:07 EDT
+1 for 3.4.1rc2, also considering how critical this is, based on comment in bug 245942: "After trying to save the file it becomes impossible to reopen it as
java file."
Comment 12 Jerome Lanneluc CLA 2008-09-03 06:50:03 EDT
Created attachment 111567 [details]
Same fix and test for R3_4_maintenance
Comment 13 Jerome Lanneluc CLA 2008-09-03 07:55:12 EDT
(In reply to comment #12)
Fix and test released for 3.4.1

Comment 14 David Audel CLA 2008-09-04 08:50:03 EDT
Verified for 3.4.1 using M20080903-2000 build
Comment 15 Olivier Thomann CLA 2008-09-15 10:19:46 EDT
Verified for 3.5M2 using I20080914-2000