org.eclipse.rap icon indicating copy to clipboard operation
org.eclipse.rap copied to clipboard

`NullPointerException`: Cannot invoke `IProgressMonitor.beginTask(String, int)` because `monitor` is null

Open hangum opened this issue 1 year ago • 4 comments

I am getting a null point error in monitor.beginTask("Beging prograss", IProgressMonitor.UNKNOWN);. Repeat the NullPointException occurred and worked fine throughout the code that uses Job. The code below has been working for a long time. When it worked, it was using RAP 3.14.0.20200824, Java 1.8, Tomcat 8.5.x.

Where should I look?
Thanks in advance.

Environment:

  • EcliseRAP : rap-3.27.0-RC2a-20231205-1650
  • Tomcat : Apache Tomcat 9.0.86 or Tomcat 10.x
  • Java : Java 17.x or 21.x

Error description:

java.lang.NullPointerException: Cannot invoke "org.eclipse.core.runtime.IProgressMonitor.beginTask(String, int)" because "monitor" is null
	at com.xxxxTadpoleTableComposite$8.run(xxxTableComposite.java:733)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

Sample Code:

final String MSG_LoadingData = CommonMessages.get().LoadingData;
	Job job = new Job(CommonMessages.get().ExecuteQuery) {
		@Override
		public IStatus run(IProgressMonitor monitor) {
			monitor.beginTask(MSG_LoadingData, IProgressMonitor.UNKNOWN);  <-----  null point exception
			
			try {
				listTablesDAO = TadpoleObjectQuery.getTableList(userDB);
			} catch(Exception e) {
				logger.error("Table Referesh", e); //$NON-NLS-1$
				
				return new Status(Status.WARNING, Activator.PLUGIN_ID, e.getMessage(), e);
			} finally {
				monitor.done();
			}
			
			return Status.OK_STATUS;
		}
	};
	
	job.addJobChangeListener(new JobChangeAdapter() {
		
		public void done(IJobChangeEvent event) {
			final IJobChangeEvent jobEvent = event; 
			
			final Display display = getSite().getShell().getDisplay();
			display.asyncExec(new Runnable() {
				public void run() {
					if(jobEvent.getResult().isOK()) {
						xxx
					} else {
						xxxx
					}	// end else if
					
					
				}	// end run
			});	// end display.asyncExec
			
		}	// end done
		
		
		
	});	// end job
	
	job.setName(userDB.getDisplay_name());
	job.setUser(false);
	job.schedule();

hangum avatar Feb 24 '24 18:02 hangum

I modified the runtime to rap-3.22.0-R-20220906-0913 and it works fine. I'll share a test site when I'm done with my busy work.

Thanks.

hangum avatar Feb 27 '24 08:02 hangum

Thank you for your report! Since you mention a "modified runtime" in your last comment: Can you share with us what you have changed, or even better, create a pull request?

mknauer avatar Feb 28 '24 10:02 mknauer

We may have stumbled across the same problem: monitor == null. Unfortunately, we don't have a minimal standalone example to reproduce the problem. I suspect the problem is due to the following commit in the eclipse platform: https://github.com/eclipse-platform/eclipse.platform/commit/9c3525cbd3fbd1e2618e8c9edf4871f5c8d70cb2

Previously, a NullProgressMonitor was used in the platform if a ProgressProvider returned null. In RAP, at least in our case, the RAP-specific org.eclipse.rap.ui.internal.progress.JobManagerAdapter is called, which returns null under certain conditions. At first glance, RAP behaves as before, only the eclipse platform now handles null results differently, which leads to these subsequent errors.

A quick fix could be to add the NullProgressMonitor fallback handling to the RAP specific JobManagerAdapter.

dogla avatar Apr 04 '24 08:04 dogla

See https://github.com/eclipse-platform/eclipse.platform/pull/1282

dogla avatar Apr 04 '24 09:04 dogla

Fixed in RAP 3.29 by using the latest platform bundle with the fix.

ifurnadjiev avatar Jul 08 '24 11:07 ifurnadjiev

@ifurnadjiev Thanks

hangum avatar Jul 08 '24 11:07 hangum