Skip to content
This repository was archived by the owner on Dec 4, 2025. It is now read-only.

When using the JsonNaming annotation, if the value is not specified, a null pointer exception will occur during the build process. #1103

@NinthCode

Description

@NinthCode

Contact Details

[email protected]

Version

3.1.1

Plugin

smart-doc-maven-plugin

Build tool version

3.8.8

Jdk version

Java(TM) SE Runtime Environment (build 1.8.0_381-b09) Java HotSpot(TM) 64-Bit Server VM (build 25.381-b09, mixed mode)

Describe the bug (Bug描述,社区已开启国际化推广,请用千问、星火等免费大模型工具辅助翻译成英文,减少社区开发者的工作)

When using the JsonNaming annotation, if the value is not specified, a null pointer exception will occur during the build process.
The version of Jackson is 2.13.5.

@JsonNaming
@Data
public class ThirdStoreListRequest implements Serializable {
    private Integer storeType;
}

Debugging revealed that in the translate method of the PropertyNameHelper class, when retrieving the value from the annotation, if JsonNaming does not explicitly set the value, it returns null, leading to a null pointer exception.

public static PropertyNamingStrategies.NamingBase translate(List<JavaAnnotation> javaAnnotations) {
		for (JavaAnnotation annotation : javaAnnotations) {
			String simpleAnnotationName = annotation.getType().getValue();
			// jackson
			if (DocAnnotationConstants.JSON_NAMING.equalsIgnoreCase(simpleAnnotationName)) {
				String value = annotation.getProperty("value").getParameterValue().toString().toLowerCase();
				return jackSonTranslate(value);
			}

		}
		return null;
	}

Expected Behavior (您期望的结果,社区已开启国际化推广,请用千问、星火等免费大模型工具辅助翻译成英文,减少社区开发者的工作)

It builds successfully.

Current Behavior (当前结果,社区已开启国际化推广,请用文心一言、讯飞星火等辅助翻译成英文,减少社区开发者的工作)

[ERROR] 
java.lang.NullPointerException
    at com.ly.doc.extension.json.PropertyNameHelper.translate (PropertyNameHelper.java:90)
    at com.ly.doc.helper.ParamsBuildHelper.processFields (ParamsBuildHelper.java:220)
    at com.ly.doc.helper.ParamsBuildHelper.buildParams (ParamsBuildHelper.java:163)
    at com.ly.doc.template.IRestDocTemplate.requestParams (IRestDocTemplate.java:1313)
    at com.ly.doc.template.IRestDocTemplate.buildEntryPointMethod (IRestDocTemplate.java:850)
    at com.ly.doc.template.IRestDocTemplate.processApiData (IRestDocTemplate.java:176)
    at com.ly.doc.template.SpringBootDocBuildTemplate.renderApi (SpringBootDocBuildTemplate.java:63)
    at com.ly.doc.template.IDocBuildTemplate.getApiData (IDocBuildTemplate.java:56)
    at com.ly.doc.builder.openapi.AbstractOpenApiBuilder.getOpenApiDocs (AbstractOpenApiBuilder.java:646)
    at com.ly.doc.builder.openapi.OpenApiBuilder.buildOpenApi (OpenApiBuilder.java:94)
    at com.ly.doc.plugin.mojo.OpenApiMojo.executeMojo (OpenApiMojo.java:46)
    at com.ly.doc.plugin.mojo.BaseDocsGeneratorMojo.execute (BaseDocsGeneratorMojo.java:163)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:255)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:201)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:361)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:314)
    at org.codehaus.classworlds.Launcher.main (Launcher.java:41)

Steps to Reproduce (Bug产生步骤,请尽量提供用例代码。社区已开启国际化推广,请用文心一言、讯飞星火等辅助翻译成英文,减少社区开发者的工作)

use java 1.8
use jackson 2.13.5
use springboot 2.3..5.RELEASE
use lombok
add bean

@Data
@JsonNaming
public class EmailInsureTaskGroupPO {
    private Integer taskType;

    private Integer flowStatus;

    private Long num;
}

build
mvn smart-doc:openapi -Dfile.encoding=UTF-8 -pl :xxx -am -X

Possible Solution (Bug解决建议,社区已开启国际化推广,请用文心一言、讯飞星火等辅助翻译成英文,减少社区开发者的工作)

Add a conditional check - when unable to retrieve the value, return null.

Context (Bug影响描述,社区已开启国际化推广,请用文心一言、讯飞星火等辅助翻译成英文,减少社区开发者的工作)

Failed to build.

Validations

  • Check if you're on the latest smart-doc version. (请检查是否为最新版本)
  • Read the docs. (请先阅读官方文档)
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate. (检查是否存在报告相同错误的问题,以避免产生重复)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions