Skip to content

Commit dcaa9b2

Browse files
committed
Eliminate publicLookup helper.
This seemed helpful, but it probably causes more harm than good by causing confusing errors when publicLookup doesn't have the required access. Better to make the caller pass a Lookup object that has the required access.
1 parent cd0e56e commit dcaa9b2

File tree

7 files changed

+21
-37
lines changed

7 files changed

+21
-37
lines changed

libs/x-content/src/main/java/org/elasticsearch/xcontent/ConstructingObjectParser.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -158,26 +158,6 @@ public static <R extends Record, Context> ConstructingObjectParser<R, Context> f
158158
return new ConstructingObjectParser<>(name, ignoreUnknownFields, (args, context) -> builder.apply(args));
159159
}
160160

161-
/**
162-
* Build a parser for the given {@code recordClass}.
163-
*
164-
* @param name The name given to the delegate ObjectParser for error identification. Use what you'd use if the object worked with
165-
* ObjectParser.
166-
* @param ignoreUnknownFields Should this parser ignore unknown fields? This should generally be set to true only when parsing responses
167-
* from external systems, never when parsing requests from users.
168-
* @param recordClass the {@link Class} of the {@link Record} type to build.
169-
* It must be a public class with a public canonical constructor, in a package that is exported unconditionally;
170-
* otherwise, you'll need {@link #forRecord(String, boolean, Class, MethodHandles.Lookup)} instead.
171-
* @return a function suitable to use as the {@code builder} argument for one of the constructors of this class.
172-
*/
173-
public static <R extends Record, Context> ConstructingObjectParser<R, Context> forRecord(
174-
String name,
175-
boolean ignoreUnknownFields,
176-
Class<R> recordClass
177-
) {
178-
return forRecord(name, ignoreUnknownFields, recordClass, MethodHandles.publicLookup());
179-
}
180-
181161
private static <R extends Record> Function<Object[], R> recordBuilder(Class<R> recordClass, MethodHandles.Lookup lookup) {
182162
Class<?>[] ctorArgs = Arrays.stream(recordClass.getRecordComponents()).map(RecordComponent::getType).toArray(Class<?>[]::new);
183163
MethodHandle ctor;

modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/direct/DatabaseConfiguration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.elasticsearch.xcontent.XContentParser;
2626

2727
import java.io.IOException;
28+
import java.lang.invoke.MethodHandles;
2829
import java.nio.charset.StandardCharsets;
2930
import java.util.Arrays;
3031
import java.util.Objects;
@@ -262,7 +263,8 @@ public String getWriteableName() {
262263
private static final ConstructingObjectParser<Maxmind, Void> PARSER = ConstructingObjectParser.forRecord(
263264
"maxmind",
264265
false,
265-
Maxmind.class
266+
Maxmind.class,
267+
MethodHandles.lookup()
266268
);
267269

268270
static {

server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamAutoShardingEvent.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.elasticsearch.xcontent.XContentParser;
2222

2323
import java.io.IOException;
24+
import java.lang.invoke.MethodHandles;
2425
import java.util.function.LongSupplier;
2526

2627
/**
@@ -39,7 +40,8 @@ public record DataStreamAutoShardingEvent(String triggerIndexName, int targetNum
3940
public static final ConstructingObjectParser<DataStreamAutoShardingEvent, Void> PARSER = ConstructingObjectParser.forRecord(
4041
"auto_sharding",
4142
false,
42-
DataStreamAutoShardingEvent.class
43+
DataStreamAutoShardingEvent.class,
44+
MethodHandles.lookup()
4345
);
4446

4547
static {

server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamFailureStore.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.elasticsearch.xcontent.XContentParser;
2626

2727
import java.io.IOException;
28+
import java.lang.invoke.MethodHandles;
2829

2930
/**
3031
* Holds the data stream failure store metadata that enable or disable the failure store of a data stream. Currently, it
@@ -47,7 +48,8 @@ public record DataStreamFailureStore(@Nullable Boolean enabled, @Nullable DataSt
4748
public static final ConstructingObjectParser<DataStreamFailureStore, Void> PARSER = ConstructingObjectParser.forRecord(
4849
FAILURE_STORE,
4950
false,
50-
DataStreamFailureStore.class
51+
DataStreamFailureStore.class,
52+
MethodHandles.lookup()
5153
);
5254

5355
static {

server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamOptions.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.elasticsearch.xcontent.XContentParser;
2525

2626
import java.io.IOException;
27+
import java.lang.invoke.MethodHandles;
2728

2829
import static org.elasticsearch.cluster.metadata.DataStreamFailureStore.FAILURE_STORE;
2930

@@ -45,7 +46,8 @@ public record DataStreamOptions(@Nullable DataStreamFailureStore failureStore)
4546
public static final ConstructingObjectParser<DataStreamOptions, Void> PARSER = ConstructingObjectParser.forRecord(
4647
"options",
4748
false,
48-
DataStreamOptions.class
49+
DataStreamOptions.class,
50+
MethodHandles.lookup()
4951
);
5052

5153
static {

server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadataStats.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.elasticsearch.xcontent.XContentParser;
2424

2525
import java.io.IOException;
26+
import java.lang.invoke.MethodHandles;
2627
import java.util.Arrays;
2728
import java.util.Objects;
2829

@@ -134,7 +135,8 @@ public record AverageShardSize(long totalSizeInBytes, int numberOfShards) implem
134135
private static final ConstructingObjectParser<AverageShardSize, Void> PARSER = ConstructingObjectParser.forRecord(
135136
"average_shard_size",
136137
false,
137-
AverageShardSize.class
138+
AverageShardSize.class,
139+
MethodHandles.lookup()
138140
);
139141

140142
static {

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/profile/ProfileDocument.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.elasticsearch.xpack.core.security.user.User;
2424

2525
import java.io.IOException;
26+
import java.lang.invoke.MethodHandles;
2627
import java.nio.charset.StandardCharsets;
2728
import java.security.MessageDigest;
2829
import java.time.Instant;
@@ -125,25 +126,18 @@ public static ProfileDocument fromXContent(XContentParser parser) {
125126
return PARSER.apply(parser, null);
126127
}
127128

128-
@SuppressWarnings("unchecked")
129129
static final ConstructingObjectParser<ProfileDocumentUser, Void> PROFILE_DOC_USER_PARSER = ConstructingObjectParser.forRecord(
130130
"user_profile_document_user",
131131
false,
132-
ProfileDocumentUser.class
132+
ProfileDocumentUser.class,
133+
MethodHandles.lookup()
133134
);
134135

135-
@SuppressWarnings("unchecked")
136-
static final ConstructingObjectParser<ProfileDocument, Void> PROFILE_DOC_PARSER = new ConstructingObjectParser<>(
136+
static final ConstructingObjectParser<ProfileDocument, Void> PROFILE_DOC_PARSER = ConstructingObjectParser.forRecord(
137137
"user_profile_document",
138138
false,
139-
(args, v) -> new ProfileDocument(
140-
(String) args[0],
141-
(boolean) args[1],
142-
(long) args[2],
143-
(ProfileDocumentUser) args[3],
144-
(Map<String, Object>) args[4],
145-
(BytesReference) args[5]
146-
)
139+
ProfileDocument.class,
140+
MethodHandles.lookup()
147141
);
148142

149143
static final ConstructingObjectParser<ProfileDocument, Void> PARSER = new ConstructingObjectParser<>(

0 commit comments

Comments
 (0)