Skip to content

Fix NPE when importing config without metadata file#14795

Open
Senrian wants to merge 1 commit intoalibaba:masterfrom
Senrian:fix-npe-import-metadata
Open

Fix NPE when importing config without metadata file#14795
Senrian wants to merge 1 commit intoalibaba:masterfrom
Senrian:fix-npe-import-metadata

Conversation

@Senrian
Copy link
Copy Markdown

@Senrian Senrian commented Mar 30, 2026

Bug Description

Issue: #14785

When importing a ZIP configuration file without the required metadata file (.meta.yml or .metadata.yml), the server throws a NullPointerException:

Cannot invoke "com.alibaba.nacos.config.server.utils.ZipUtils$ZipItem.getItemData()" because "metaDataItem" is null

Root Cause

In ConfigControllerV3.parseImportDataV2(), the code directly calls metaDataItem.getItemData() without checking if metaDataItem is null.

Fix

Add a null check before accessing metaDataItem:

ZipUtils.ZipItem metaDataItem = unziped.getMetaDataItem();
Map<String, Object> failedData = new HashMap<>(4);

if (metaDataItem == null) {
    failedData.put("succCount", 0);
    return Result.failure(ErrorCode.METADATA_ILLEGAL, failedData);
}

String metaData = metaDataItem.getItemData();

Issue: alibaba#14785

Add null check for metaDataItem before calling getItemData().
@github-actions
Copy link
Copy Markdown

Thanks for your this PR. 🙏
Please check again for your PR changes whether contains any usage/api/configuration change such as Add new API , Add new configuration, Change default value of configuration.
If so, please add or update documents(markdown type) in docs/next/ for repository nacos-group/nacos-group.github.io


感谢您提交的PR。 🙏
请再次查看您的PR内容,确认是否包含任何使用方式/API/配置参数的变更,如:新增API新增配置参数修改默认配置等操作。
如果是,请确保在提交之前,在仓库nacos-group/nacos-group.github.io中的docs/next/目录下添加或更新文档(markdown格式)。

@KomachiSion
Copy link
Copy Markdown
Collaborator

I don't get the reason why add a new api to do metadata?

@Senrian
Copy link
Copy Markdown
Author

Senrian commented Apr 6, 2026

Hi @KomachiSion, this PR does not add a new API. It only adds a null check in the existing parseImportDataV2() method. When a ZIP file without .meta.yml/.metadata.yml is uploaded, metaDataItem becomes null and causes NPE at metaDataItem.getItemData(). The fix simply returns an error result with ErrorCode.METADATA_ILLEGAL instead of crashing. No new API is introduced.

@KomachiSion
Copy link
Copy Markdown
Collaborator

Please change the basic branch to develop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants