Skip to content

Commit 711c7bc

Browse files
committed
re-enable jdk9 collections support.
1 parent c98038e commit 711c7bc

5 files changed

Lines changed: 29 additions & 21 deletions

File tree

value-fixture/test-java-11/org/immutables/fixture/nullable/NullableAttributesTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,13 @@ public void nullValuesInJdkMapErrorMsg() {
349349
try {
350350
ImmutableEntityWithMap.builder().properties(new HashMap<>()).build().withProperties(properties);
351351
} catch (NullPointerException e) {
352-
check(e.getMessage()).is("value for key: b");
352+
boolean isJava8 = System.getProperty("java.version").startsWith("1.8");
353+
if (isJava8) {
354+
check(e.getMessage()).is("properties value for key: b");
355+
} else {
356+
// Java 9+ copy methods NPE has no message
357+
check(e.getMessage()).isNull();
358+
}
353359
}
354360
try {
355361
ImmutableEntityWithMap.builder().putAllProperties(properties).build();

value-fixture/test/org/immutables/fixture/jackson/ObjectMappedTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import com.fasterxml.jackson.core.type.TypeReference;
1919
import com.fasterxml.jackson.databind.ObjectMapper;
20+
import com.fasterxml.jackson.databind.SerializationFeature;
2021
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
2122
import com.fasterxml.jackson.datatype.guava.GuavaModule;
2223
import java.io.IOException;
@@ -27,7 +28,8 @@
2728
public class ObjectMappedTest {
2829
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
2930
{
30-
OBJECT_MAPPER.registerModule(new GuavaModule());
31+
OBJECT_MAPPER.registerModule(new GuavaModule())
32+
.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);
3133
}
3234

3335
public static class Wrapper {

value-fixture/test/org/immutables/fixture/jdkonly/JdkOnlyTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ public void collections() {
4848
.addPols(RetentionPolicy.RUNTIME, RetentionPolicy.RUNTIME)
4949
.build();
5050

51-
check(coll.ints()).isOf(1, 2, 3, 4, 5, 6);
52-
check(coll.navs()).isOf(3, 2, 1);
53-
check(coll.ords()).isOf(4, 5, 6, 7, 8, 9);
54-
check(coll.pols()).isOf(RetentionPolicy.RUNTIME);
51+
check(coll.ints()).hasContentInAnyOrder(1, 2, 3, 4, 5, 6);
52+
check(coll.navs()).hasContentInAnyOrder(3, 2, 1);
53+
check(coll.ords()).hasContentInAnyOrder(4, 5, 6, 7, 8, 9);
54+
check(coll.pols()).hasContentInAnyOrder(RetentionPolicy.RUNTIME);
5555
}
5656

5757
@Test
@@ -111,9 +111,9 @@ public void maps() {
111111
.putAllOrds(ImmutableMap.of(2, "2", 1, "1"))
112112
.build();
113113

114-
check(maps.navs().keySet()).isOf("33", "22");
115-
check(maps.just().keySet()).isOf(1L, 2L);
116-
check(maps.ords().keySet()).isOf(1, 2);
114+
check(maps.navs().keySet()).hasContentInAnyOrder("33", "22");
115+
check(maps.just().keySet()).hasContentInAnyOrder(1L, 2L);
116+
check(maps.ords().keySet()).hasContentInAnyOrder(1, 2);
117117
}
118118

119119
@Test

value-processor/src/org/immutables/value/processor/Immutables.generator

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2442,8 +2442,13 @@ return [type.factoryOf]([output.linesShortable][for v in type.settableAttributes
24422442
[if v.nullable][expression][else][expression].clone()[/if]
24432443
[else if v.attributeValueKindCopy]
24442444
[if v.nullable][expression] == null ? null : [/if][deepCopyOf v][expression][/deepCopyOf]
2445-
[else if v.collectionType or v.mapType]
2445+
[else if v.mapType]
24462446
[if v.nullable][expression] == null ? null : [/if][immutableCollectionCopyOf v expression]
2447+
[else if v.collectionType]
2448+
[if v.nullable][expression] == null ? null : [/if][if v.isGenerateJdk9][expression] instanceof java.util.Collection<?>
2449+
? java.util.[v.rawCollectionType].copyOf((java.util.Collection<[v.consumedElementType]>) [expression])
2450+
: java.util.stream.StreamSupport.stream([expression].spliterator(), false)
2451+
.collect(java.util.stream.Collectors.toUnmodifiable[v.rawCollectionType]())[else][immutableCollectionCopyOf v expression][/if]
24472452
[else]
24482453
[maybeCopyOf v][maybeNonNullValue v][expression][/maybeNonNullValue][/maybeCopyOf]
24492454
[/if]

value-processor/src/org/immutables/value/processor/meta/ValueType.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,8 @@ public boolean isGenerateJdkOnly() {
275275
return style().jdkOnly() || noGuavaInClasspath();
276276
}
277277

278-
// Until we can fix copy constructors generation for new Java9 collections
279-
private static final boolean java9CollectionsEnabled = Boolean.getBoolean("immutables.java9-collections");
280-
281278
public boolean isGenerateJdk9() {
282-
return java9CollectionsEnabled && constitution.protoclass().environment().hasJava9Collections();
279+
return constitution.protoclass().environment().hasJava9Collections();
283280
}
284281

285282
public boolean isGenerateBuildOrThrow() {
@@ -1162,12 +1159,10 @@ public boolean apply(ValueAttribute attribute) {
11621159
&& !attribute.isGuavaImmutableDeclared();
11631160
if (def) {
11641161
switch (kind) {
1165-
case MAP:
1166-
case LIST:
1167-
case SET:
1168-
return !attribute.isGenerateJdk9();
1169-
default:
1170-
return true;
1162+
case MAP:
1163+
return !attribute.isGenerateJdk9();
1164+
default:
1165+
return true;
11711166
}
11721167
}
11731168
return false;
@@ -1867,7 +1862,7 @@ public Reporter report() {
18671862
public List<String> getDebugLines() {
18681863
return constitution.protoclass().getDebugLines();
18691864
}
1870-
1865+
18711866
public boolean isDataInline() {
18721867
return DataInlineMirror.isPresent(element);
18731868
}

0 commit comments

Comments
 (0)