Hum .. sorry .. too early in the morning for me .. Ledger is a hibernate entity class and T5 should not be involved.
I'll be right back ... 2011/9/3 Gunnar Eketrapp <gunnar.eketr...@gmail.com> > Hi ! > > I have been happily hacking web sites with T5 for a year and half now and > is more then pleased! > Kudos to all of you for this excellent web framework that makes coding fun > again. > > And I have never ever encountered any defect in the T5 code. > > Now to my problem. > > I just got an error in an onActivate method that looked like it could not > happen. > > When steeping through it in my debugger I really get puzzled. > > A variable assigned inside a block is null after leaving the block. > > It must have something to do with the "plastering" of my code. Or !? > > The error I get is .. > > Caused by: java.lang.NullPointerException > at > utskicket.pages.economy.EditYear._$advised$onActivate_13(EditYear.java:91) > > ... and in the debugger I can see that ledger is null at line 91. > > In the code below I have commented what happens in the debugger. > > Can anyone understand what could cause this error ... > I have stepped through the generated code without seeing anything strange. > It all looks great but when returning ledger is null. > > Do I break any rule / convention with my code !? > > Many many thanks in advance, > Gunnar Eketrapp, Stockholm, Sweden > > Environment: > *jdk 1.6.0_22* > *t5.2.6* > *windows 7 proffesional, 32-bit* > > > @Property > private Ledger ledger; > > @Property > private String notice; > > // > ------------------------------------------------------------------------------ > // -- Tapestry event methods - Tapestry event methods - Tapestry event > methods -- > // > ------------------------------------------------------------------------------ > > @Log > Object onActivate(long groupId, long ledgerId) { > > group = groupDAO.findById(groupId); > if (group == null) > return Index.class; > > if (ledgerId != 0) { > ledger = ledgerDAO.findById(ledgerId); > if (ledger == null) > return Index.class; > if (!same(group.getId(), ledger.getGroup().getId())) > return Index.class; > > hasPrevious = (null != ledgerDAO.findPrevious(ledger)); > hasNext = (null != ledgerDAO.findNext(ledger)); > transactionCount = transactionDAO.countTransactions(ledger); > > } else { > ledger = new Ledger(); * // 1: This one returns null !!!* > Ledger lastLedger = ledgerDAO.findLast(group); > if (null == lastLedger) { > UTDate today = new UTDate(); > ledger.setStartDate(new UTDate(today.getYear(), 1, 1)); *// > 2: This line ends the block!* > ledger.setEndDate(new UTDate(today.getYear(), 12, 31)); > } else { > > ledger.setStartDate(lastLedger.getStartDate().warpYears(1)); > ledger.setEndDate(lastLedger.getEndDate().warpYears(1)); > } > } > > * if (ledger.getClosed()) // 3: And here we crash!* > notice = "Året är stängt och kan inte ändras"; > else { > if (!mayEdit()) > notice = "Endast det senaste året kan ändras."; > else if (!mayEditStarts()) > notice = "Startdagen kan inte ändras då det finns tidigare > år."; > } > > return null; > } > > -- [Hem: 08-715 59 57, Mobil: 070-991 86 42] Allévägen 2A, 132 42 Saltsjö-Boo