Skip to content

Commit e1884c6

Browse files
authored
Merge pull request #799 from ngmr/refactor/use-empty-array-singletons
refactor: use empty array singletons
2 parents ec2c607 + 323e8ef commit e1884c6

68 files changed

Lines changed: 619 additions & 203 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

testify-iiop/src/main/java/testify/iiop/Skellington.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 IBM Corporation and others.
2+
* Copyright 2026 IBM Corporation and others.
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.
@@ -43,7 +43,6 @@
4343
import java.util.Arrays;
4444
import java.util.Set;
4545
import java.util.TreeSet;
46-
import java.util.stream.Collectors;
4746
import java.util.stream.Stream;
4847

4948
public abstract class Skellington extends Servant implements Tie, Remote {
@@ -53,8 +52,7 @@ public Skellington() {
5352
final ValueHandler vh = Util.createValueHandler();
5453
this.ids = findRemoteInterfaces(this.getClass())
5554
.map(vh::getRMIRepositoryID)
56-
.collect(Collectors.toList())
57-
.toArray(new String[0]);
55+
.toArray(String[]::new);
5856
}
5957

6058
private static Stream<Class<? extends Remote>> findRemoteInterfaces(final Class<?> forClass) {

testify-iiop/src/main/java/testify/iiop/annotation/ConfigureOrb.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.lang.annotation.Inherited;
2525
import java.lang.annotation.Retention;
2626
import java.lang.annotation.Target;
27+
28+
import static org.apache.yoko.util.Arrays.NO_STRINGS;
2729
import java.util.Optional;
2830

2931
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
@@ -46,7 +48,7 @@ enum NameService {
4648
private final String initializerClassName;
4749

4850
NameService() {
49-
this.args = new String[0];
51+
this.args = NO_STRINGS;
5052
this.initializerClassName = null;
5153
}
5254

testify-iiop/src/main/java/testify/iiop/annotation/ServerSteward.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import static java.util.stream.Collectors.joining;
5656
import static java.util.stream.Collectors.toSet;
5757
import static javax.rmi.PortableRemoteObject.narrow;
58+
import static org.apache.yoko.util.Arrays.NO_STRINGS;
5859
import static org.hamcrest.CoreMatchers.anyOf;
5960
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
6061
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -276,8 +277,7 @@ private String[] buildJvmArgs() {
276277
args.add("--add-opens");
277278
args.add("java.base/java.util=ALL-UNNAMED");
278279
}
279-
280-
return args.toArray(new String[0]);
280+
return args.toArray(NO_STRINGS);
281281
}
282282

283283
private String buildClasspathForVersion(String version) {

yoko-core/src/main/java/org/apache/yoko/orb/CORBA/Delegate.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import org.omg.CORBA.NO_RESPONSE;
4141
import org.omg.CORBA.OBJECT_NOT_EXIST;
4242
import org.omg.CORBA.Policy;
43+
44+
import static org.apache.yoko.util.Arrays.emptyArray;
4345
import org.omg.CORBA.PolicyListHolder;
4446
import org.omg.CORBA.REBIND;
4547
import org.omg.CORBA.SetOverrideType;
@@ -75,7 +77,7 @@
7577

7678
public final class Delegate extends org.omg.CORBA_2_4.portable.Delegate {
7779
private static final Logger logger = Logger.getLogger(Delegate.class.getName());
78-
private static final Policy[] EMPTY_POLICY_ARRAY = new Policy[0];
80+
7981
private final ORBInstance orbInstance;
8082
private IOR ior;
8183
private IOR origIor;
@@ -448,7 +450,7 @@ public org.omg.CORBA.Object set_policy_override(org.omg.CORBA.Object self, Polic
448450
// now overwrite/add the new policies
449451
for (Policy p : np) policiesByType.put(p.policy_type(), p);
450452
// copy the policies that survived into a new array
451-
newPolicies = policiesByType.values().toArray(EMPTY_POLICY_ARRAY);
453+
newPolicies = policiesByType.values().toArray(emptyArray(Policy.class));
452454
}
453455

454456
final Delegate p = new Delegate(orbInstance, ior, origIor, newPolicies);
@@ -554,7 +556,7 @@ public Policy[] get_policy_overrides(org.omg.CORBA.Object self, int[] types) {
554556
}
555557
}
556558

557-
return list.toArray(EMPTY_POLICY_ARRAY);
559+
return list.toArray(emptyArray(Policy.class));
558560
}
559561

560562
public Policy get_client_policy(org.omg.CORBA.Object self, int type) {

yoko-core/src/main/java/org/apache/yoko/orb/CORBA/PolicyMap.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 IBM Corporation and others.
2+
* Copyright 2026 IBM Corporation and others.
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.
@@ -19,23 +19,25 @@
1919

2020
import org.omg.CORBA.Policy;
2121

22+
import static org.apache.yoko.util.Arrays.emptyArray;
23+
2224
import java.util.ArrayList;
2325
import java.util.List;
2426
import java.util.TreeMap;
2527

2628
public class PolicyMap extends TreeMap<Integer, Policy> {
27-
private static final Policy[] ZERO_POLICIES_ARRAY = new Policy[0];
29+
2830

2931
public PolicyMap(PolicyMap m) { super(m); }
3032
public PolicyMap(Policy...policies) { for (Policy p: policies) add(p); }
3133

3234
public void add(Policy p) { put(p.policy_type(), p); }
3335

34-
public Policy[] getAllPolicies() { return values().toArray(ZERO_POLICIES_ARRAY); }
36+
public Policy[] getAllPolicies() { return values().toArray(emptyArray(Policy.class)); }
3537

3638
public Policy[] getSomePolicies(int[] types) {
3739
List<Policy> list = new ArrayList<>();
3840
for (int type: types) if (containsKey(type)) list.add(get(type));
39-
return list.toArray(ZERO_POLICIES_ARRAY);
41+
return list.toArray(emptyArray(Policy.class));
4042
}
4143
}

yoko-core/src/main/java/org/apache/yoko/orb/CORBA/StubForObject.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 IBM Corporation and others.
2+
* Copyright 2026 IBM Corporation and others.
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.
@@ -20,13 +20,15 @@
2020
import org.omg.CORBA.portable.IDLEntity;
2121
import org.omg.CORBA_2_4.portable.ObjectImpl;
2222

23+
import static org.apache.yoko.util.Arrays.NO_STRINGS;
24+
2325
final public class StubForObject extends ObjectImpl
2426
implements IDLEntity {
2527
// ------------------------------------------------------------------
2628
// Standard IDL to Java Mapping
2729
// ------------------------------------------------------------------
2830

2931
public String[] _ids() {
30-
return new String[0];
32+
return NO_STRINGS;
3133
}
3234
}

yoko-core/src/main/java/org/apache/yoko/orb/CORBA/StubForRemote.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 IBM Corporation and others.
2+
* Copyright 2026 IBM Corporation and others.
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.
@@ -17,13 +17,13 @@
1717
*/
1818
package org.apache.yoko.orb.CORBA;
1919

20+
import javax.rmi.CORBA.Stub;
2021
import java.rmi.Remote;
2122

22-
import javax.rmi.CORBA.Stub;
23+
import static org.apache.yoko.util.Arrays.NO_STRINGS;
2324

2425
public class StubForRemote extends Stub implements Remote {
25-
public String[] _ids() {
26-
return new String[0];
27-
}
28-
26+
public String[] _ids() {
27+
return NO_STRINGS;
28+
}
2929
}

yoko-core/src/main/java/org/apache/yoko/orb/CORBA/YokoOutputStream.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
import org.omg.IOP.IORHelper;
5151
import org.omg.IOP.TaggedProfile;
5252

53+
import static org.apache.yoko.util.Arrays.emptyArray;
54+
5355
import java.io.Serializable;
5456
import java.math.BigDecimal;
5557
import java.util.Enumeration;
@@ -666,7 +668,7 @@ public void write_Object(org.omg.CORBA.Object value) {
666668
MARSHAL_OUT_LOG.finest(() -> "Writing a null CORBA object value");
667669
IOR ior = new IOR();
668670
ior.type_id = "";
669-
ior.profiles = new TaggedProfile[0];
671+
ior.profiles = emptyArray(TaggedProfile.class);
670672
IORHelper.write(this, ior);
671673
} else {
672674
if (value instanceof LocalObject)

yoko-core/src/main/java/org/apache/yoko/orb/CosNaming/NamingContextBase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import static java.util.Objects.requireNonNull;
5050
import static java.util.logging.Level.WARNING;
5151
import static java.util.stream.Collectors.joining;
52+
import static org.apache.yoko.util.Arrays.emptyArray;
5253
import static org.apache.yoko.logging.VerboseLogging.NAMING_LOG;
5354
import static org.apache.yoko.util.MinorCodes.MinorObjectIsNull;
5455
import static org.omg.CORBA.CompletionStatus.COMPLETED_NO;
@@ -457,7 +458,7 @@ else if (ch == '/') {
457458
components.add(new NameComponent(id, kind));
458459

459460
// and turn this into a component array
460-
return components.toArray(new NameComponent[0]);
461+
return components.toArray(emptyArray(NameComponent.class));
461462
}
462463

463464
/**

yoko-core/src/main/java/org/apache/yoko/orb/CosNaming/tnaming/TransientNamingContext.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import org.omg.CosNaming.BindingIteratorPOA;
3939
import org.omg.CosNaming.BindingListHolder;
4040
import org.omg.CosNaming.NameComponent;
41+
42+
import static org.apache.yoko.util.Arrays.emptyArray;
4143
import org.omg.CosNaming.NamingContextHelper;
4244
import org.omg.CosNaming.NamingContext;
4345

@@ -397,7 +399,7 @@ public boolean next_one(BindingHolder b) {
397399
}
398400
else {
399401
// return an empty element
400-
b.value = new Binding(new NameComponent[0], BindingType.nobject);
402+
b.value = new Binding(emptyArray(NameComponent.class), BindingType.nobject);
401403
return false;
402404
}
403405
}

0 commit comments

Comments
 (0)