Skip to content

Commit a1d88e6

Browse files
authored
Rename ClusterState#lookupPrototypeSafe to lookupPrototype and remove previous "unsafe" unused variant (#21686)
The `lookupPrototype` method is not used anywhere. Seems like we rather use its `lookupProrotypeSafe` variant (which also throws exception if the prototype is not found) is always. This commit makes the safer variant the default one, by renaming it to "lookupPrototype" and removes the previous "unsafe" variant.
1 parent d913242 commit a1d88e6

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

core/src/main/java/org/elasticsearch/cluster/ClusterState.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,7 @@ public static void registerPrototype(String type, Custom proto) {
108108
registerPrototype(RestoreInProgress.TYPE, RestoreInProgress.PROTO);
109109
}
110110

111-
@Nullable
112111
public static <T extends Custom> T lookupPrototype(String type) {
113-
//noinspection unchecked
114-
return (T) customPrototypes.get(type);
115-
}
116-
117-
public static <T extends Custom> T lookupPrototypeSafe(String type) {
118112
@SuppressWarnings("unchecked")
119113
T proto = (T) customPrototypes.get(type);
120114
if (proto == null) {
@@ -308,7 +302,7 @@ public enum Metric {
308302

309303
private final String value;
310304

311-
private Metric(String value) {
305+
Metric(String value) {
312306
this.value = value;
313307
}
314308

@@ -630,10 +624,6 @@ public Builder stateUUID(String uuid) {
630624
return this;
631625
}
632626

633-
public Custom getCustom(String type) {
634-
return customs.get(type);
635-
}
636-
637627
public Builder putCustom(String type, Custom custom) {
638628
customs.put(type, custom);
639629
return this;
@@ -707,7 +697,7 @@ public ClusterState readFrom(StreamInput in, DiscoveryNode localNode) throws IOE
707697
int customSize = in.readVInt();
708698
for (int i = 0; i < customSize; i++) {
709699
String type = in.readString();
710-
Custom customIndexMetaData = lookupPrototypeSafe(type).readFrom(in);
700+
Custom customIndexMetaData = lookupPrototype(type).readFrom(in);
711701
builder.putCustom(type, customIndexMetaData);
712702
}
713703
return builder.build();
@@ -779,12 +769,12 @@ public ClusterStateDiff(StreamInput in, ClusterState proto) throws IOException {
779769
new DiffableUtils.DiffableValueSerializer<String, Custom>() {
780770
@Override
781771
public Custom read(StreamInput in, String key) throws IOException {
782-
return lookupPrototypeSafe(key).readFrom(in);
772+
return lookupPrototype(key).readFrom(in);
783773
}
784774

785775
@Override
786776
public Diff<Custom> readDiff(StreamInput in, String key) throws IOException {
787-
return lookupPrototypeSafe(key).readDiffFrom(in);
777+
return lookupPrototype(key).readDiffFrom(in);
788778
}
789779
});
790780
}

0 commit comments

Comments
 (0)