From 376c70ddc1e227f0572edfa2d51a5cf8dd0e429c Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Thu, 2 Apr 2020 19:44:31 -0400 Subject: [PATCH] Workaround JDK 14 compiler bug (#54689) This commit workarounds a bug in the JDK 14 compiler. It is choking on a method reference, so we substitute a lambda expression instead. The JDK bug ID is 9064309. --- .../example/customsuggester/CustomSuggestion.java | 6 +++++- .../search/suggest/completion/CompletionSuggestion.java | 6 +++++- .../search/suggest/phrase/PhraseSuggestion.java | 6 +++++- .../elasticsearch/search/suggest/term/TermSuggestion.java | 6 +++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/plugins/examples/custom-suggester/src/main/java/org/elasticsearch/example/customsuggester/CustomSuggestion.java b/plugins/examples/custom-suggester/src/main/java/org/elasticsearch/example/customsuggester/CustomSuggestion.java index 05c7880e9ec24..b238651039ab6 100644 --- a/plugins/examples/custom-suggester/src/main/java/org/elasticsearch/example/customsuggester/CustomSuggestion.java +++ b/plugins/examples/custom-suggester/src/main/java/org/elasticsearch/example/customsuggester/CustomSuggestion.java @@ -95,7 +95,11 @@ public static class Entry extends Suggest.Suggestion.Entry entry.dummy = dummy, DUMMY); - PARSER.declareObjectArray(Entry::addOptions, (p, c) -> Option.fromXContent(p), new ParseField(OPTIONS)); + /* + * The use of a lambda expression instead of the method reference Entry::addOptions is a workaround for a JDK 14 compiler bug. + * The bug ID is 9064309. + */ + PARSER.declareObjectArray((e, o) -> e.addOptions(o), (p, c) -> Option.fromXContent(p), new ParseField(OPTIONS)); } private String dummy; diff --git a/server/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestion.java b/server/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestion.java index 0115ec79b435f..02bc4ba6001d7 100644 --- a/server/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestion.java +++ b/server/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestion.java @@ -264,7 +264,11 @@ protected Option newOption(StreamInput in) throws IOException { Entry::new); static { declareCommonFields(PARSER); - PARSER.declareObjectArray(Entry::addOptions, (p,c) -> Option.fromXContent(p), new ParseField(OPTIONS)); + /* + * The use of a lambda expression instead of the method reference Entry::addOptions is a workaround for a JDK 14 compiler bug. + * The bug ID is 9064309. + */ + PARSER.declareObjectArray((e, o) -> e.addOptions(o), (p,c) -> Option.fromXContent(p), new ParseField(OPTIONS)); } public static Entry fromXContent(XContentParser parser) { diff --git a/server/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestion.java b/server/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestion.java index fe7c03b11b1ec..fcb7a0cff0343 100644 --- a/server/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestion.java +++ b/server/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestion.java @@ -123,7 +123,11 @@ public void addOption(Option option) { private static final ObjectParser PARSER = new ObjectParser<>("PhraseSuggestionEntryParser", true, Entry::new); static { declareCommonFields(PARSER); - PARSER.declareObjectArray(Entry::addOptions, (p, c) -> Option.fromXContent(p), new ParseField(OPTIONS)); + /* + * The use of a lambda expression instead of the method reference Entry::addOptions is a workaround for a JDK 14 compiler bug. + * The bug ID is 9064309. + */ + PARSER.declareObjectArray((e, o) -> e.addOptions(o), (p, c) -> Option.fromXContent(p), new ParseField(OPTIONS)); } public static Entry fromXContent(XContentParser parser) { diff --git a/server/src/main/java/org/elasticsearch/search/suggest/term/TermSuggestion.java b/server/src/main/java/org/elasticsearch/search/suggest/term/TermSuggestion.java index 665c95cd47eb3..d860f1cb405f3 100644 --- a/server/src/main/java/org/elasticsearch/search/suggest/term/TermSuggestion.java +++ b/server/src/main/java/org/elasticsearch/search/suggest/term/TermSuggestion.java @@ -182,7 +182,11 @@ protected Option newOption(StreamInput in) throws IOException { private static final ObjectParser PARSER = new ObjectParser<>("TermSuggestionEntryParser", true, Entry::new); static { declareCommonFields(PARSER); - PARSER.declareObjectArray(Entry::addOptions, (p,c) -> Option.fromXContent(p), new ParseField(OPTIONS)); + /* + * The use of a lambda expression instead of the method reference Entry::addOptions is a workaround for a JDK 14 compiler bug. + * The bug ID is 9064309. + */ + PARSER.declareObjectArray((e, o) -> e.addOptions(o), (p, c) -> Option.fromXContent(p), new ParseField(OPTIONS)); } public static Entry fromXContent(XContentParser parser) {