Repository: alibaba/nacos (2026-04-13T04:18:23Z)

Issue:
# Bug Report: Config Import Fails with "metaDataItem is null" Error
# Bug Report: Config Import Fails with "metaDataItem is null" Error

## Description

The configuration import feature in Nacos 3.x console does not work properly. When attempting to import configurations via ZIP file, the server returns an error indicating that `metaDataItem` is null. Additionally, the exported ZIP files from the console also lack the necessary `meta_data` file, making it impossible to re-import exported configurations.

## Steps to Reproduce

### Case 1: Importing a manually created ZIP file

1. Create a ZIP file with the following structure:
   ```
   config.zip
   ├── DEFAULT_GROUP/
   │   └── application.yml
   └── meta_data
   ```
   Where `meta_data` contains:
   ```
   DEFAULT_GROUP|application.yml|
   ```

2. Go to Nacos Console → Configuration Management
3. Click "Import" button
4. Select the ZIP file
5. The import fails with error

### Case 2: Importing an exported ZIP file

1. Create a configuration in Nacos Console (e.g., `test.yml` in `DEFAULT_GROUP`)
2. Select the configuration and click "Export"
3. Try to import the exported ZIP file
4. The import fails with the same error

## Expected Behavior

The ZIP file should be imported successfully, and configurations should appear in the configuration list.

## Actual Behavior

Import fails with the following error response:

```json
{
  "code": 30000,
  "message": "Cannot invoke \"com.alibaba.nacos.config.server.utils.ZipUtils$ZipItem.getItemData()\" because \"metaDataItem\" is null",
  "data": null
}
```

## Environment

- **Nacos Version**: 3.1.2
- **Deployment Mode**: Standalone
- **Java Version**: JDK 17+
- **OS**: macOS / Linux

## Root Cause Analysis

After investigation, the issue appears to be:

1. **Export Bug**: When exporting configurations, the generated ZIP file does NOT include the `meta_data` file that is required for import. The exported ZIP only contains the configuration files in group directories.

2. **Import Bug**: The import function expects a `meta_data` file in the ZIP, but even when providing a correctly formatted `meta_data` file, the import still fails. This suggests there may be an issue in how `ZipUtils.java` parses or locates the `meta_data` file.

### Exported ZIP Structure (Current - Incorrect)
```
nacos_config_export.zip
└── DEFAULT_GROUP/
    └── config.yml    (no meta_data file!)
```

### Expected ZIP Structure (Correct)
```
nacos_config_export.zip
├── DEFAULT_GROUP/
│   └── config.yml
└── meta_data         (required!)
```

## Workaround

Use the API to create configurations individually:

```bash
curl -s "http://localhost:8080/v3/console/cs/config?accessToken=${TOKEN}&username=nacos" \
  -X 'POST' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  --data-urlencode 'dataId=application.yml' \
  --data-urlencode 'groupName=DEFAULT_GROUP' \
  --data-urlencode 'namespaceId=' \
  --data-urlencode 'content=<config_content>' \
  --data-urlencode 'type=yaml'
```

## Suggested Fix

1. Fix the export function to include `meta_data` file with proper format:
   ```
   GROUP|dataId|tenantId
   ```

2. Fix the import function (`ZipUtils.java`) to correctly locate and parse the `meta_data` file from the ZIP archive.

## Related Files

- `config/src/main/java/com/alibaba/nacos/config/server/utils/ZipUtils.java`
- `config/src/main/java/com/alibaba/nacos/config/server/controller/ConfigController.java`

## Additional Context

This bug makes the bulk configuration import/export feature completely unusable in Nacos 3.x, which is a critical feature for:
- Migrating configurations between environments
- Backup and restore operations
- Bulk configuration deployment

---

**Would you like me to provide a sample ZIP file or test configurations to help debug this issue?**


Discussion:
This issue has been open 7 days with no activity. This will be closed in 7 days.



Patch:
diff --git a/console/src/main/java/com/alibaba/nacos/console/handler/impl/inner/config/ConfigInnerHandler.java b/console/src/main/java/com/alibaba/nacos/console/handler/impl/inner/config/ConfigInnerHandler.java
index 1cef0688af..25b855530b 100644
--- a/console/src/main/java/com/alibaba/nacos/console/handler/impl/inner/config/ConfigInnerHandler.java
+++ b/console/src/main/java/com/alibaba/nacos/console/handler/impl/inner/config/ConfigInnerHandler.java
@@ -334,8 +334,12 @@ public Result<Map<String, Object>> importAndPublishConfig(String srcUser, String
     private Result<Map<String, Object>> parseImportDataV2(String srcUser, ZipUtils.UnZipResult unziped,
             List<ConfigAllInfo> configInfoList, List<Map<String, String>> unrecognizedList, String namespace) {
         ZipUtils.ZipItem metaDataItem = unziped.getMetaDataItem();
-        String metaData = metaDataItem.getItemData();
         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();
         
         ConfigMetadata configMetadata = YamlParserUtil.loadObject(metaData, ConfigMetadata.class);
         if (configMetadata == null || CollectionUtils.isEmpty(configMetadata.getMetadata())) {


Test patch:
diff --git a/console/src/test/java/com/alibaba/nacos/console/handler/impl/inner/config/ConfigInnerHandlerTest.java b/console/src/test/java/com/alibaba/nacos/console/handler/impl/inner/config/ConfigInnerHandlerTest.java
index c527e1aec4..cbd12bfa5e 100644
--- a/console/src/test/java/com/alibaba/nacos/console/handler/impl/inner/config/ConfigInnerHandlerTest.java
+++ b/console/src/test/java/com/alibaba/nacos/console/handler/impl/inner/config/ConfigInnerHandlerTest.java
@@ -337,6 +337,18 @@ void importAndPublishConfigWithoutMetadata() throws NacosException {
             assertEquals(ErrorCode.METADATA_ILLEGAL.getCode(), actual.getCode());
         }
     }
+
+    @Test
+    void importAndPublishConfigWithNullMetadataItem() throws NacosException {
+        ZipUtils.UnZipResult unziped = new ZipUtils.UnZipResult(new ArrayList<>(), null);
+        MockMultipartFile file = new MockMultipartFile("file", "test.zip", "application/zip", "test".getBytes());
+        try (MockedStatic<ZipUtils> zipUtilsMockedStatic = Mockito.mockStatic(ZipUtils.class)) {
+            zipUtilsMockedStatic.when(() -> ZipUtils.unzip(eq(file.getBytes()))).thenReturn(unziped);
+            Result<Map<String, Object>> actual = configInnerHandler.importAndPublishConfig("srcUser", "public",
+                    SameConfigPolicy.OVERWRITE, file, "srcIp", "requestIpApp");
+            assertEquals(ErrorCode.METADATA_ILLEGAL.getCode(), actual.getCode());
+        }
+    }
     
     @Test
     void importAndPublishConfigWithWrongMetadata() throws NacosException {