'ERROR org.quartz.core.JobRunShell - Job group1.JobReport threw an unhandled Exception

There is a strange problem when generating the report using QUARTZ scheduler

I can generate a report fine! no problem.

the method (reportsBean) works normally, but there is a problem when passing through quartz

Any idea please?? I don't know what to do anymore :/

13449 [MyScheduler_Worker-1] ERROR org.quartz.core.JobRunShell - Job group1.JobReport threw an unhandled Exception: java.lang.NullPointerException at com.changes.bean.ReportsBean.createPdfCriticalChanges(ReportsBean.java:104) at com.changes.quartz.JobReport.execute(JobReport.java:36) at org.quartz.core.JobRunShell.run(JobRunShell.java:202) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) 13452 [MyScheduler_Worker-1] ERROR org.quartz.core.ErrorLogger - Job (group1.JobReport threw an exception. org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.NullPointerException] at org.quartz.core.JobRunShell.run(JobRunShell.java:213) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) Caused by: java.lang.NullPointerException at com.changes.bean.ReportsBean.createPdfCriticalChanges(ReportsBean.java:104) at com.changes.quartz.JobReport.execute(JobReport.java:36) at org.quartz.core.JobRunShell.run(JobRunShell.java:202)

reportsbean

public class JobReport implements Job {


    public void execute(JobExecutionContext context) throws JobExecutionException {


        //BasicConfigurator.configure();
        try {
            ReportsBean reportsBean = new ReportsBean();
            reportsBean.createPdfCriticalChanges();
            SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy – hh:mm:ss");
            System.out.println("Rodou: " + dateFormat.format( new Date() ));
        } catch (JRException | SQLException e) {
            e.printStackTrace();
        }

    }

}

quartz.properties

org.quartz.scheduler.instanceName = MyScheduler
org.quartz.threadPool.threadCount = 3
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
org.quartz.plugin.jobInitializer.class =org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.jobInitializer.fileNames = com/changes/quartz/quartz-config.xml
org.quartz.plugin.jobInitializer.failOnFileNotFound = true

web.xml

<!-- Inicio Quartz -->
<servlet>
    <servlet-name>QuartzServlet</servlet-name>
    <servlet-class>com.changes.quartz.servlet.QuartzServlet</servlet-class>
</servlet>
<servlet>
    <servlet-name>QuartzInitializer</servlet-name>
    <servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class>
    <init-param>
        <param-name>config-file</param-name>
        <param-value>quartz.properties</param-value>
    </init-param>
    <init-param>
        <param-name>shutdown-on-unload</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>start-scheduler-on-load</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
</servlet>
<!-- Fim Quartz -->


Solution 1:[1]

The Problem is that you have a NullPointerException in your ReportsBean.

Since the signature of the Quartz execute method is

public void execute(JobExecutionContext context) throws JobExecutionException

Quartz can only deal with JobExecutionException's that will be thrown within this method. But in your case it gets an unexpected NullPointerException.

To solve this Problem you should remove the cause of the NullPointer. From the sourcecode above I couldnt figure out the cause of this exception since it occurs within your ReportsBean.

Certainly your method ReportsBean.createPdfCriticalChanges trys to access an uninitialized member.

Solution 2:[2]

at the line 104: String report FacesContext.getCurrentInstance().getExternalContext().getRealPath("/web/reports/criticalcr.jrxml");

Remember: it's working out of quartz.

ReportsBean

public void createPdfCriticalChanges() throws JRException,SQLException {
            System.out.println("generating report...");

            String report = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/web/reports/criticalcr.jrxml");
            JasperReport pathjrxml = JasperCompileManager.compileReport(report);
            //JasperReport pathjrxml = JasperCompileManager.compileReport("web/reports/criticalcr.jrxml"); //Funciona com o inicia Agenda em XML "web/reports/changetracker_criticalcr.jrxml"
            JasperPrint printReport = JasperFillManager.fillReport(pathjrxml, null, conn.getConn());
            JasperExportManager.exportReportToPdfFile(printReport, "/web/reports/changetracker_criticalcr.pdf"); //Funciona com o inicia Agenda em XML "web/reports/criticalcr.pdf"
            System.out.println("report generated!");
    }

Solution 3:[3]

it's not throws JobExecutionExceptionnb use @postController and @override method init

Solution 4:[4]

I had same issue, I solved by putting time greater than current time in table that stores next_fire_time. then restart the server.

Solution 5:[5]

ReportsBean is not able to create an object on this place. If it's a Spring application please use @Autowired annotations to fix this issue:

@Autowired
ReportsBean reportsBean;

Then use call reportsBean.yourMethod();.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 rafa120
Solution 3 Purushottam
Solution 4 munjal007
Solution 5 colidyre