From d1fdef654993fe6dfdd644aaacd760b3c43df68c Mon Sep 17 00:00:00 2001 From: Noorul Misbah Date: Sun, 23 Aug 2026 12:23:03 +0800 Subject: [PATCH 1/2] fix: handle null schemaType in SwaggerSchemaMapper.assignType for composed schemas Set.of() rejects null values, causing an NPE when a composed schema (allOf/oneOf/anyOf) has no explicit type. Added null check before calling Set.of(schemaType). Also improved warning log messages in DefaultChannelsService and DefaultOperationsService to show exception class name when message is null, making startup errors easier to diagnose. Fixes #1834 --- .../channels/DefaultChannelsService.java | 6 +++++- .../operations/DefaultOperationsService.java | 6 +++++- .../asyncapi/schemas/SwaggerSchemaMapper.java | 2 +- .../components/SwaggerSchemaMapperTest.java | 16 ++++++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/channels/DefaultChannelsService.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/channels/DefaultChannelsService.java index ac062287c..e2ec90895 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/channels/DefaultChannelsService.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/channels/DefaultChannelsService.java @@ -34,7 +34,11 @@ public Map findChannels() { Map channels = scanner.scan(); foundChannelItems.addAll(channels.values()); } catch (Exception e) { - log.warn("An error was encountered during channel scanning with {}: {}", scanner, e.getMessage(), e); + log.warn( + "An error was encountered during channel scanning with {}: {}", + scanner, + e.getMessage() != null ? e.getMessage() : e.getClass().getSimpleName(), + e); } } return ChannelMerger.mergeChannels(foundChannelItems); diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/operations/DefaultOperationsService.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/operations/DefaultOperationsService.java index 8b3c728cb..a14b174f0 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/operations/DefaultOperationsService.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/operations/DefaultOperationsService.java @@ -34,7 +34,11 @@ public Map findOperations() { Map channels = scanner.scan(); foundOperations.addAll(channels.values()); } catch (Exception e) { - log.warn("An error was encountered during operation scanning with {}: {}", scanner, e.getMessage(), e); + log.warn( + "An error was encountered during operation scanning with {}: {}", + scanner, + e.getMessage() != null ? e.getMessage() : e.getClass().getSimpleName(), + e); } } return OperationMerger.mergeOperations(foundOperations); diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/schemas/SwaggerSchemaMapper.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/schemas/SwaggerSchemaMapper.java index ca31f7ed4..f10285c76 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/schemas/SwaggerSchemaMapper.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/schemas/SwaggerSchemaMapper.java @@ -207,7 +207,7 @@ private static void assignType(Schema swaggerSchema, SchemaObject.SchemaObjectBu String schemaType = swaggerSchema.getType(); if (!types.contains(schemaType)) { // required while swagger v2 does not populate types - builder.type(Set.of(schemaType)); + builder.type(schemaType == null ? Set.of() : Set.of(schemaType)); return; } diff --git a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/SwaggerSchemaMapperTest.java b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/SwaggerSchemaMapperTest.java index 74b856717..1822cb32b 100644 --- a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/SwaggerSchemaMapperTest.java +++ b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/SwaggerSchemaMapperTest.java @@ -223,6 +223,21 @@ void mapType() { assertThat(componentSchema.getSchema().getType()).containsExactly(schema.getType()); } + @Test + void mapNullTypeForComposedSchema() { + // given + Schema schema = new Schema<>(); + // no type set - simulates a composed schema (allOf/oneOf/anyOf) with null type + schema.addAllOfItem(new Schema<>()); + + // when + ComponentSchema componentSchema = swaggerSchemaMapper.mapSchema(schema); + + // then - should not throw NPE, type should be empty + assertThat(componentSchema.getSchema()).isNotNull(); + assertThat(componentSchema.getSchema().getType()).isNullOrEmpty(); + } + @Test void mapProperties() { // given @@ -639,6 +654,7 @@ void mapMaxItems() { @Nested class MapToSwagger { + @Test void mapNameAndTitle() { // given From 63b693e398feee26a5c34c98d16d9df166ab3176 Mon Sep 17 00:00:00 2001 From: Noorul Misbah Date: Mon, 24 Aug 2026 02:24:22 +0000 Subject: [PATCH 2/2] revert: remove logging improvement per maintainer feedback --- .../core/asyncapi/channels/DefaultChannelsService.java | 6 +----- .../core/asyncapi/operations/DefaultOperationsService.java | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/channels/DefaultChannelsService.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/channels/DefaultChannelsService.java index e2ec90895..ac062287c 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/channels/DefaultChannelsService.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/channels/DefaultChannelsService.java @@ -34,11 +34,7 @@ public Map findChannels() { Map channels = scanner.scan(); foundChannelItems.addAll(channels.values()); } catch (Exception e) { - log.warn( - "An error was encountered during channel scanning with {}: {}", - scanner, - e.getMessage() != null ? e.getMessage() : e.getClass().getSimpleName(), - e); + log.warn("An error was encountered during channel scanning with {}: {}", scanner, e.getMessage(), e); } } return ChannelMerger.mergeChannels(foundChannelItems); diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/operations/DefaultOperationsService.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/operations/DefaultOperationsService.java index a14b174f0..8b3c728cb 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/operations/DefaultOperationsService.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/operations/DefaultOperationsService.java @@ -34,11 +34,7 @@ public Map findOperations() { Map channels = scanner.scan(); foundOperations.addAll(channels.values()); } catch (Exception e) { - log.warn( - "An error was encountered during operation scanning with {}: {}", - scanner, - e.getMessage() != null ? e.getMessage() : e.getClass().getSimpleName(), - e); + log.warn("An error was encountered during operation scanning with {}: {}", scanner, e.getMessage(), e); } } return OperationMerger.mergeOperations(foundOperations);