Skip to content

Commit 156b28b

Browse files
authored
Deserialization disabled by default. (helidon-io#4334)
Added serial config where required. MP Config uses known class for converters (to avoid lambdas and complex deserialization)
1 parent ac032df commit 156b28b

8 files changed

Lines changed: 104 additions & 32 deletions

File tree

common/common/src/main/java/io/helidon/common/SerializationConfig.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021 Oracle and/or its affiliates.
2+
* Copyright (c) 2021, 2022 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -126,7 +126,7 @@ public static Builder builder() {
126126
* This is a one-off call to set up global filter.
127127
*/
128128
public static void configureRuntime() {
129-
builder().build().configure();
129+
builder().onNoConfig(Action.CONFIGURE).build().configure();
130130
}
131131

132132
/**
@@ -366,8 +366,8 @@ public enum TraceOption {
366366
* {@link SerializationConfig#configureRuntime()} directly.
367367
*/
368368
public static class Builder implements io.helidon.common.Builder<Builder, SerializationConfig> {
369-
private Action onWrongConfig = configuredAction(PROP_WRONG_CONFIG_ACTION, Action.WARN);
370-
private Action onNoConfig = configuredAction(PROP_NO_CONFIG_ACTION, Action.WARN);
369+
private Action onWrongConfig = configuredAction(PROP_WRONG_CONFIG_ACTION, Action.FAIL);
370+
private Action onNoConfig = configuredAction(PROP_NO_CONFIG_ACTION, Action.FAIL);
371371
private String filterPattern = System.getProperty(PROP_PATTERN);
372372
private TraceOption traceSerialization = configuredTrace(TraceOption.NONE);
373373
private boolean ignoreFiles = Boolean.getBoolean(PROP_IGNORE_FILES);
@@ -621,6 +621,10 @@ public Status checkInput(FilterInfo filterInfo) {
621621
}
622622
Status result = delegate.checkInput(filterInfo);
623623

624+
if (clazz == null) {
625+
return result;
626+
}
627+
624628
if (!reportedClasses.add(clazz)) {
625629
if (basic) {
626630
return result;

common/common/src/test/java/io/helidon/common/SerializationConfigTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021 Oracle and/or its affiliates.
2+
* Copyright (c) 2021, 2022 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,10 +34,8 @@ void testDefaults() {
3434

3535
SerializationConfig.ConfigOptions options = serializationConfig.options();
3636
assertThat(options.traceSerialization(), is(SerializationConfig.TraceOption.NONE));
37-
// TODO this will change in 3.0.0
38-
assertThat(options.onNoConfig(), is(SerializationConfig.Action.WARN));
39-
// TODO this will change in 3.0.0
40-
assertThat(options.onWrongConfig(), is(SerializationConfig.Action.WARN));
37+
assertThat(options.onNoConfig(), is(SerializationConfig.Action.FAIL));
38+
assertThat(options.onWrongConfig(), is(SerializationConfig.Action.FAIL));
4139
assertThat(options.filterPattern(), is("!*"));
4240
}
4341

config/config-mp/src/main/java/io/helidon/config/mp/MpConfigBuilder.java

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2021 Oracle and/or its affiliates.
2+
* Copyright (c) 2020, 2022 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -668,11 +668,46 @@ private static class OrdinalConverter {
668668
private OrdinalConverter(Converter<?> converter, Class<?> aClass, int ordinal) {
669669
this.ordinal = ordinal;
670670
this.type = aClass;
671-
this.converter = converter;
671+
this.converter = new NullCheckingConverter<>(aClass, converter);
672672
}
673673

674674
private OrdinalConverter(Converter<?> converter) {
675675
this(converter, getConverterType(converter.getClass()), Priorities.find(converter, 100));
676676
}
677+
678+
@Override
679+
public String toString() {
680+
return type.getName() + "->" + converter;
681+
}
682+
}
683+
684+
private static final class NullCheckingConverter<T> implements Converter<T> {
685+
private final Converter<T> delegate;
686+
private final Class<?> type;
687+
688+
private NullCheckingConverter(Class<?> type, Converter<T> delegate) {
689+
this.delegate = delegate;
690+
this.type = type;
691+
}
692+
693+
@Override
694+
public T convert(String value) throws IllegalArgumentException, NullPointerException {
695+
if (value == null) {
696+
throw new NullPointerException("Null not allowed in MP converters. Converter for type " + type.getName());
697+
}
698+
699+
try {
700+
return delegate.convert(value);
701+
} catch (IllegalArgumentException | NullPointerException e) {
702+
throw e;
703+
} catch (Exception e) {
704+
throw new IllegalArgumentException("Cannot convert value", e);
705+
}
706+
}
707+
708+
@Override
709+
public String toString() {
710+
return type.getName() + "->" + delegate;
711+
}
677712
}
678713
}

config/config-mp/src/main/java/io/helidon/config/mp/MpConfigImpl.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2021 Oracle and/or its affiliates.
2+
* Copyright (c) 2020, 2022 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -260,19 +260,6 @@ private <T> Optional<Converter<T>> findComponentConverter(Class<T> type) {
260260
.findFirst()
261261
.map(Map.Entry::getValue)
262262
.map(it -> (Converter<T>) it)
263-
.map(it -> (Converter<T>) value -> {
264-
if (value == null) {
265-
throw new NullPointerException("Null not allowed in MP converters. Converter for type " + forType
266-
.getName());
267-
}
268-
try {
269-
return it.convert(value);
270-
} catch (IllegalArgumentException e) {
271-
throw e;
272-
} catch (Exception e) {
273-
throw new IllegalArgumentException("Cannot convert value", e);
274-
}
275-
})
276263
.or(() -> findImplicit(forType));
277264
}
278265

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Copyright (c) 2022 Oracle and/or its affiliates.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
# The JBatch uses Serialization a lot, and these are all required
18+
pattern=com.ibm.jbatch.**;jakarta.batch.runtime.BatchStatus;java.lang.Enum;\
19+
java.util.Properties;java.util.Hashtable;java.util.Map$Entry

examples/jbatch/src/main/resources/logging.properties

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,3 @@ java.util.logging.SimpleFormatter.format=%1$tY.%1$tm.%1$td %1$tH:%1$tM:%1$tS %4$
2828

2929
# Quiet Weld
3030
org.jboss.level=WARNING
31-
32-
# Component specific log levels
33-
#io.helidon.webserver.level=INFO
34-
#io.helidon.config.level=INFO
35-
#io.helidon.security.level=INFO
36-
#io.helidon.common.level=INFO
37-
#io.netty.level=INFO
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# Copyright (c) 2022 Oracle and/or its affiliates.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
pattern=org.jboss.weld.bean.proxy.util.SerializableClientProxy;org.jboss.weld.bean.StringBeanIdentifier;\
18+
org.eclipse.microprofile.config.Config$_$$_WeldClientProxy;io.helidon.config.mp.MpConfigBuilder$NullCheckingConverter
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# Copyright (c) 2022 Oracle and/or its affiliates.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
# TCK converter to validate deserialization
18+
pattern=org.eclipse.microprofile.config.tck.converters.DuckConverter;org.eclipse.microprofile.config.tck.converters.Duck

0 commit comments

Comments
 (0)