掲題のようなエラーが出てきてしまいました。
具体的な事象
レジアプリを作っています。
レシート履歴情報取得という機能を実装中に掲題のエラーメッセージが発生しました。
Debug際に、下記ソースコードにある太字の【ReceiptInfoResp.Data.GoodsList goods = new ReceiptInfoResp.Data.GoodsList();】の箇所でF6を押下し次の行に進めようとして際に、下記ソースコードにある太字の【if (conn != null) {】まで実行されてしまいました。
Java初心者ですが、コードが問題ないように見えましたが、Debugしてもなかなか原因が特定できない状態です。
わかる方がいればご教示のほうよろしくお願い致します。
エラーメッセージ
2023/04/14 15:53:14.648 [INFO ] (00000013-00000005) HTTP-REQUEST (GET,-,-1,127.0.0.1) [/] 2023/04/14 15:53:14.654 [DEBUG] (00000013-00000005) Page action [jp.co.forestec.favgolf.web.page.Default] 2023/04/14 15:53:14.666 [WARN ] (00000013-00000005) ClassNotFoundException [jp.co.forestec.favgolf.web.page.NotFound] 2023/04/14 15:53:14.667 [INFO ] (00000013-00000005) HTTP-RESPONSE (404,-1,-) [21]ms 2023/04/14 15:53:15.117 [INFO ] (0000001A-00000006) HTTP-REQUEST (GET,-,-1,0:0:0:0:0:0:0:1) [/api/register/receipt-info] 2023/04/14 15:53:15.124 [INFO ] (0000001A-00000006) HTTP-RESPONSE (405,-1,-) [7]ms 2023/04/14 15:53:30.064 [INFO ] (00000018-00000007) HTTP-REQUEST (POST,text/plain,21,0:0:0:0:0:0:0:1) [//api/register/receipt-info] 2023/04/14 15:53:42.869 [INFO ] (00000018-00000007) SQL [SELECT * FROM t_receipt WHERE RECEIPT_ID = 3333 ] 2023/04/14 15:53:43.149 [INFO ] (00000018-00000007) SQL実行時間 [276] msec 2023/04/14 15:53:50.320 [INFO ] (00000018-00000007) SQL [(SELECT trc.receipt_details_id AS receiptContentsId, ti.item_name AS goodsName, ti.item_price AS goodsPrice, trc.item_count AS goodsCount, trc.price AS goodsTotal FROM t_receipt_contents trc LEFT OUTER JOIN t_item ti ON trc.item_id = ti.item_id WHERE trc.receipt_id = 3333 AND trc.item_id <> 0 AND trc.box_price_id is null) UNION ALL (SELECT trc.receipt_details_id AS receiptContentsId, cast(mb.box_name as text) AS goodsName, mbp.box_price AS goodsPrice, trc.item_count AS goodsCount, trc.price AS goodsTotal FROM t_receipt_contents trc LEFT OUTER JOIN m_box_price mbp ON mbp.box_price_id = trc.box_price_id LEFT OUTER JOIN m_box mb ON mb.box_id = mbp.box_id WHERE trc.receipt_id = 3333 AND trc.box_price_id <> 0 AND trc.item_id is null) UNION ALL (SELECT trc.receipt_details_id AS receiptContentsId, mlp.lesson_name AS goodsName, mclp.price AS goodsPrice, trc.item_count AS goodsCount, trc.price AS goodsTotal FROM t_receipt_contents trc LEFT OUTER JOIN m_coach_lesson_price mclp ON mclp.coach_lesson_price_id = trc.coach_lesson_price_id LEFT OUTER JOIN m_lesson_plan mlp ON mlp.lesson_plan_id = mclp.lesson_plan_id WHERE trc.receipt_id = 3333 AND trc.coach_lesson_price_id <> 0 AND trc.item_id is null) UNION ALL (SELECT trc.receipt_details_id AS receiptContentsId, tc.coupon_name AS goodsName, '0' AS goodsPrice, '1' AS goodsCount, trc.price AS goodsTotal FROM t_receipt_contents trc LEFT OUTER JOIN t_coupon tc ON tc.coupon_id = trc.coupon_id WHERE trc.receipt_id = 3333 AND trc.record_status = 1 AND trc.price is not null) ] 2023/04/14 15:53:50.387 [INFO ] (00000018-00000007) SQL実行時間 [65] msec 2023/04/14 16:09:36.644 [INFO ] (00000018-00000007) HTTP-RESPONSE (200,-1,-) [966575]ms 重大: パス [] を持つコンテキスト内のサーブレット [ReceiptInfo] のServlet.service() が例外 [サーブレットの実行により例外を投げました] が根本的要因と共に投げられました [金 4 14 16:09:37 JST 2023]
該当のソースコード
/** * * レシート情報履歴取得 * */ public class ReceiptInfo extends ServletBase { /** * */ private static final long serialVersionUID = 368711852743059517L; @Override public void init() throws ServletException { setRequestMask(ServletBase.REQ_MASK_POST); } @Override protected void doPost(RequestController rcntl) throws ServletException, IOException { JSON jsonic = new JSON(); jsonic.setSuppressNull(true); BufferedOutputStream bos = null; Connection conn = null; try { conn = rcntl.getConnection(Favgolf.DB_NAME); bos = new BufferedOutputStream(rcntl.getResponse().getOutputStream()); ReceiptInfoResp resp = new ReceiptInfoResp(); resp.setResult(ReceiptInfoResp.RC_SYSTEM_ERROR); resp.setMessage("予期しないエラーが発生しました"); try { logic: { byte[] bodyData = rcntl.getReqRowData(); if (bodyData == null) { break logic; } ReceiptInfoReq req = jsonic.parse(new String(bodyData), ReceiptInfoReq.class); req.validate(rcntl); ReceiptInfoManager mgr = new ReceiptInfoManager(conn, rcntl.getLogger()); Receipt receiptSummary = mgr.getReceiptInfoSummary(req.getReceiptId()); ArrayList<ReceiptInfoGoodsList> receiptGoodsList = mgr.getReceiptInfoGoodsList(req.getReceiptId()); //正常返却 ReceiptInfoResp.Data data = new ReceiptInfoResp.Data(); data.setReceiptId(receiptSummary.getReceiptId()); data.setAccountingDate(receiptSummary.getAccountingDate()); data.setPaymentMethod(receiptSummary.getPaymentMethod()); data.setTotal(receiptSummary.getTotal()); ArrayList<ReceiptInfoResp.Data.GoodsList> respGoodsList = new ArrayList<>(); for (ReceiptInfoGoodsList ReceiptInfo : receiptGoodsList) { **ReceiptInfoResp.Data.GoodsList goods = new ReceiptInfoResp.Data.GoodsList();** goods.setGoodsName(ReceiptInfo.getGoodsName()); goods.setGoodsPrice(ReceiptInfo.getGoodsPrice()); goods.setGoodsCount(ReceiptInfo.getGoodsCount()); goods.setGoodsTotal(ReceiptInfo.getGoodsTotal()); respGoodsList.add(goods); } data.setGoodsList(respGoodsList); resp.setData(data); resp.setResult(ReceiptInfoResp.RC_SUCCESS); resp.setMessage(""); } } catch (ValidateConfigException e) { rcntl.getLogger().error(e, e.getMessage()); } catch (ValidateErrorException e) { rcntl.getLogger().error(e, e.getMessage()); } catch (SQLException e) { rcntl.getLogger().error(e, e.getMessage()); } rcntl.getResponse().setContentType("application/json"); rcntl.getResponse().setStatus(HttpStatus.SC_OK); bos.write(jsonic.format(resp).getBytes()); } catch (Exception e) { rcntl.getLogger().error(e, e.getMessage()); rcntl.getResponse().setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); } finally { **if (conn != null) {** try { rcntl.relaseConnection(conn); } catch (SQLException e) { rcntl.getLogger().error(e, e.getMessage()); rcntl.getResponse().setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); } } if (bos != null) { try { bos.close(); } catch (IOException e) { rcntl.getLogger().error(e, e.getMessage()); rcntl.getResponse().setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); } } } } }
開発環境
OS Windows10
言語 Java
開発環境 Eclipse
0 コメント