{"record":{"id":"64a898ed469cf2ec","repo":"yudaocode/SpringBoot-Labs","slug":"error","errorCode":null,"errorMessage":"没有粗面鱼丸","messagePattern":"没有粗面鱼丸","errorType":"http","errorClass":"NullPointerException","httpStatus":500,"severity":"error","filePath":"lab-23/lab-springmvc-23-02/src/main/java/cn/iocoder/springboot/lab23/springmvc/controller/UserController.java","lineNumber":73,"sourceCode":"     * 获得指定用户编号的用户\n     *\n     * 测试个问题\n     *\n     * @param id 用户编号\n     * @return 用户\n     */\n    @PostMapping(\"/get\")\n    public UserVO get3(@RequestParam(\"id\") Integer id) {\n        // 查询并返回用户\n        return new UserVO().setId(id).setUsername(UUID.randomUUID().toString());\n    }\n\n    /**\n     * 测试抛出 NullPointerException 异常\n     */\n    @GetMapping(\"/exception-01\")\n    public UserVO exception01() {\n        throw new NullPointerException(\"没有粗面鱼丸\");\n    }\n\n    /**\n     * 测试抛出 ServiceException 异常\n     */\n    @GetMapping(\"/exception-02\")\n    public UserVO exception02() {\n        throw new ServiceException(ServiceExceptionEnum.USER_NOT_FOUND);\n    }\n\n    @GetMapping(\"/do_something\")\n    public void doSomething() {\n        logger.info(\"[doSomething]\");\n    }\n\n    @GetMapping(\"/current_user\")\n    public UserVO currentUser() {\n        logger.info(\"[currentUser]\");","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/yudaocode/SpringBoot-Labs/blob/6c12efaed06d12907a0f40dd2ad1f7020aec8798/lab-23/lab-springmvc-23-02/src/main/java/cn/iocoder/springboot/lab23/springmvc/controller/UserController.java#L55-L91","documentation":"This is an intentionally thrown NullPointerException from the demo endpoint GET /user/exception-01 in a Spring MVC lab project. It is not a real defect: the lab uses it to demonstrate how an uncaught runtime exception propagates through DispatcherServlet and how a @ControllerAdvice global handler can convert it into a unified error payload (CommonResult). Unless such a handler exists, Spring Boot maps it to HTTP 500 with the message '没有粗面鱼丸' (a joke string meaning 'no macaroni fish balls').","triggerScenarios":"Calling GET /user/exception-01 (the @GetMapping(\"/exception-01\") mapping on UserController). No parameters needed; the method body unconditionally executes throw new NullPointerException(\"没有粗面鱼丸\").","commonSituations":"Only occurs when exercising this tutorial endpoint deliberately (e.g., curl http://localhost:8080/user/exception-01). Real-world analogues: any NPE raised inside a @RequestMapping method that lacks an @ExceptionHandler(NPE.class)/global exception handler, surfacing as a whitelabel 500 error.","solutions":["Recognize this is deliberate demo code: hit the endpoint only when testing the global exception handler, never from real client code.","Confirm a @RestControllerAdvice with @ExceptionHandler(NullPointerException.class) (or a catch-all Exception handler) exists in the same app context so the response is a structured CommonResult instead of a raw 500.","If this appears in logs unexpectedly during unrelated testing, find who is calling /user/exception-01 (access log, browser tab left open) rather than debugging the stack trace itself.","For real code, eliminate NPE sources with Optional, null checks, or Objects.requireNonNull on inputs."],"exampleFix":"// before (demo, throws raw NPE)\n@GetMapping(\"/exception-01\")\npublic UserVO exception01() {\n    throw new NullPointerException(\"没有粗面鱼丸\");\n}\n\n// after (convert to unified error via global handler)\n@RestControllerAdvice\npublic class GlobalExceptionHandler {\n    @ExceptionHandler(NullPointerException.class)\n    public CommonResult<?> handleNpe(NullPointerException ex) {\n        return CommonResult.error(ServiceExceptionEnum.INTERNAL_SERVER_ERROR);\n    }\n}","handlingStrategy":"try-catch","validationCode":"// No pre-call validation possible: endpoint throws unconditionally.\n// Guard the demo from real traffic instead:\n// application.yaml: only map demo servlet in dev\n# spring.profiles.active: dev","typeGuard":null,"tryCatchPattern":"// In an @RestControllerAdvice (preferred over per-caller catch):\n@ExceptionHandler(NullPointerException.class)\npublic CommonResult<?> handleNpe(NullPointerException ex) {\n    logger.warn(\"NPE in handler\", ex);\n    return CommonResult.error(ServiceExceptionEnum.INTERNAL_SERVER_ERROR);\n}","preventionTips":["Never leave throw-new-NullPointerException demo endpoints reachable in production; profile-gate them.","Add a global @ControllerAdvice so any NPE becomes a structured response, not a whitelabel 500.","Initialize fields and validate inputs at the controller boundary so real NPEs surface as 400s."],"tags":["spring-mvc","tutorial","deliberate-throw","npe","exception-handler"],"backgroundTag":null,"analyzedSha":"6c12efaed06d12907a0f40dd2ad1f7020aec8798","analyzedAt":"2026-08-14T13:06:31.500Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}