2
客戶端正在通過Tomcat運行Web應用程序,並在看似無害的區域中發生異常的NullPointerException。正如您所看到的,NullPointerException不能出現在內部類BookingDetail的構造函數中。這是什麼訪問$ 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)
謝謝,我認爲NullPointerException只會拋出'at at com.empower.ess.logic.leave.LeaveCalculator.calculatePayHoursAndLeaveHoursForLSLHours(Unknown Source)',但考慮到在訪問BookingDetail專用時我沒有使用getters和setters成員這個答案是有道理的。 – mekazu 2012-02-06 04:40:28