Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7536f98

Browse files
committed
Additional null check for Option provided to factory methods generated when @Value.Parameter is used.
#27
1 parent006fe22 commit7536f98

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

‎vavr-encodings/src/main/java/org/immutables/vavr/encodings/VavrOptionEncoding.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ public Option<T> with(
4747
returnOption.some(Objects.requireNonNull(value));
4848
}
4949

50+
@Encoding.Of
51+
static <T>Option<T>init(finalOption<T>value) {
52+
Objects.requireNonNull(value);
53+
returnvalue;
54+
}
55+
5056
@Encoding.Builder
5157
staticfinalclassBuilder<T>
5258
{
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2013-2017 Immutables Authors and Contributors
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+
packageorg.immutables.vavr.examples;
18+
19+
importorg.immutables.value.Value;
20+
21+
importio.vavr.control.Option;
22+
23+
/**
24+
* An example with {@link Option} using {@link Value.Parameter} annotation
25+
*/
26+
27+
@Value.Immutable
28+
@org.immutables.vavr.encodings.VavrOptionEncodingEnabled
29+
publicinterfaceExampleOptionWithParametersType
30+
{
31+
/**
32+
* @return Some data
33+
*/
34+
@Value.Parameter
35+
Option<Integer>optionalInteger();
36+
}

‎vavr-examples/src/test/java/org/immutables/vavr/tests/examples/ExampleOptionTest.java‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
importio.vavr.control.Option;
2020
importorg.immutables.vavr.examples.ImmutableExampleOptionType;
21+
importorg.immutables.vavr.examples.ImmutableExampleOptionWithParametersType;
2122
importorg.junit.Assert;
2223
importorg.junit.Test;
2324

@@ -101,4 +102,17 @@ public void testWithNullOption()
101102
ImmutableExampleOptionType.builder().build();
102103
b.withOptionalInteger((Option<Integer>)null);
103104
}
105+
106+
@Test
107+
publicvoidtestParameter()
108+
{
109+
finalImmutableExampleOptionWithParametersTypeb =ImmutableExampleOptionWithParametersType.of(Option.of(1));
110+
Assert.assertEquals(Option.of(1),b.optionalInteger());
111+
}
112+
113+
@Test(expected =NullPointerException.class)
114+
publicvoidtestParameterWithNullOption()
115+
{
116+
finalImmutableExampleOptionWithParametersTypeb =ImmutableExampleOptionWithParametersType.of(null);
117+
}
104118
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp