Skip to content

Commit

Permalink
Fix config converter loading issue when arrays are used
Browse files Browse the repository at this point in the history
We essentially use Class.forName to load the class instead of the
ClassLoader directly, as the former knows how to deal with arrays

Fixes: quarkusio#46170
  • Loading branch information
geoand committed Feb 10, 2025
1 parent 4fe180b commit 909bf16
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected static void withDefaultValue(SmallRyeConfigBuilder builder, String nam
protected static <T> void withConverter(SmallRyeConfigBuilder builder, String type, int priority, Converter<T> converter) {
try {
// To support converters that are not public
builder.withConverter((Class<T>) builder.getClassLoader().loadClass(type), priority, converter);
builder.withConverter((Class<T>) Class.forName(type, false, builder.getClassLoader()), priority, converter);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.quarkus.config;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.nio.charset.StandardCharsets;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;

public class ByteArrayConverterTest {
@RegisterExtension
static final QuarkusUnitTest TEST = new QuarkusUnitTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class))
.overrideConfigKey("someapp.bytearray", "XyZ*123");

@ConfigProperty(name = "someapp.bytearray")
protected byte[] bytearray;

@Test
void buildTimeConfigBuilder() {
assertEquals("XyZ*123", new String(bytearray, StandardCharsets.UTF_8));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.quarkus.extest.runtime.config;

import java.nio.charset.StandardCharsets;

import org.eclipse.microprofile.config.spi.Converter;

public class ByteArrayConfigConverter implements Converter<byte[]> {

@Override
public byte[] convert(final String s) {
return s.getBytes(StandardCharsets.UTF_8);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.quarkus.extest.runtime.config.ByteArrayConfigConverter

0 comments on commit 909bf16

Please sign in to comment.