eclipse-rap / org.eclipse.rap

Eclipse RAP Runtime (Remote Application Platform)
https://www.eclipse.org/rap/
Eclipse Public License 1.0
17 stars 19 forks source link

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

Closed hangum closed 2 months ago

hangum commented 6 months ago

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:

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 commented 6 months ago

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.

mknauer commented 6 months ago

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?

dogla commented 5 months ago

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 commented 5 months ago

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

ifurnadjiev commented 2 months ago

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

hangum commented 2 months ago

@ifurnadjiev Thanks