为什么在我的私人内部类中调用$ 300()?

时间:2012-02-06 04:12:35

标签: java

客户端正在通过Tomcat运行Web应用程序,并且在看似无害的区域中获得了异常的NullPointerException。正如您所看到的,内部类BookingDetail的构造函数中不会发生NullPointerException。什么是访问$ 300()方法以及如何调用?是的,我没有行号,但我不能复制这个问题,这很烦人。

以下是LeaveCalculator类的代码片段:

private class BookingDetail {
    private Date from;
    private Date upto;
    private String wpat;
    private String pubh;
    private BookingDetail(Date from, Date upto, String wpat, String pubh) {
        this.from = from;
        this.upto = upto;
        this.wpat = wpat;
        this.pubh = pubh;
    }
}

private void calculatePayHoursAndLeaveHoursForLSLHours(Date from, Date upto) {
    String pubhMaster = ((LSLLeave) leave).getPublicHoliday().trim();
    List<PositionHistory> histories = findHistories(from, upto);
    Map<Integer, BookingDetail> table = new HashMap<Integer, BookingDetail>();
    for (PositionHistory h : histories) {
        BookingDetail position = table.get(h.getEmployment());
        if (position == null) {
            table.put(h.getEmployment(), new BookingDetail(h.getFromDate(), h.getUpToDate(), h.getWorkPatternCode(), pubhMaster.isEmpty() ? h.getPublicHolidayCode() : pubhMaster));
        } else {
            if (position.from.after(h.getFromDate()))
                position.from = h.getFromDate();
            if (position.upto.before(h.getUpToDate()))
                position.upto = h.getUpToDate();
        }    
    }
    double payHoursTotal = 0;
    double leaveHoursTotal = 0;
    boolean error = false;
    Set<Integer> keys = table.keySet();
    for (Integer employment : keys) {
        BookingDetail row = table.get(employment);
        if (row.from.before(from))
            row.from = from;
        if (row.upto.after(upto))
            row.upto = upto;
        calculatePayHoursAndLeaveHours(row, false);
        error |= !verifyLeaveHours();
        payHoursTotal += payHours;
        leaveHoursTotal += leaveHours;
    }
    leaveHours = error ? WORK_PATTERN_ERROR : leaveHoursTotal;
    payHours = payHoursTotal;
    BookingDetail lowestEmployment = table.get(employment);
    wpat = lowestEmployment.wpat;
    pubh = lowestEmployment.pubh;
}

这是堆栈跟踪:

java.lang.NullPointerException
    at com.empower.ess.logic.leave.LeaveCalculator$BookingDetail.access$300(Unknown Source)
    at com.empower.ess.logic.leave.LeaveCalculator.calculatePayHoursAndLeaveHoursForLSLHours(Unknown Source)
    at com.empower.ess.logic.leave.LeaveCalculator.calculatePayHoursAndLeaveHours(Unknown Source)
    at com.empower.ess.logic.leave.LeaveCalculator.calculateAmountToDisplay(Unknown Source)
    at com.empower.ess.logic.leave.LeaveCalculator.calculateAmountToDisplay(Unknown Source)
    at com.empower.ess.logic.leave.dwr.LeaveTypesLookup.calculateAmount(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor1190.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.empower.mawson.core.web.dwr.impl.ExecuteQuery.execute(ExecuteQuery.java:236)
    at com.empower.mawson.core.web.dwr.impl.DefaultExecProcessor.handle(DefaultExecProcessor.java:44)
    at com.empower.mawson.core.web.dwr.impl.DefaultProcessor.handle(DefaultProcessor.java:79)
    at com.empower.mawson.core.web.dwr.AbstractDWRServlet.doPost(AbstractDWRServlet.java:151)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
    at org.apache.coyote.ajp.AjpAprProcessor.process(AjpAprProcessor.java:444)
    at org.apache.coyote.ajp.AjpAprProtocol$AjpConnectionHandler.process(AjpAprProtocol.java:472)
    at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1286)
    at java.lang.Thread.run(Thread.java:619)

1 个答案:

答案 0 :(得分:3)

“access $ 300()”调用是一种合成方法,可以访问私有成员,这里可能是“from”,“upto”,“wpat”或“pubh”。其中一个在循环遍历for-each循环时可能为null。例如,在进一步取消引用它之前,您需要验证“row.from”是否为null。