Skip to content

Commit

Permalink
Workaround JDK 14 compiler bug (#54689)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jasontedor committed Apr 3, 2020
1 parent 3205d2b commit e889ea8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ public static class Entry extends Suggest.Suggestion.Entry<CustomSuggestion.Entr
static {
declareCommonFields(PARSER);
PARSER.declareString((entry, dummy) -> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ public void addOption(Option option) {
private static final ObjectParser<Entry, Void> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ protected Option newOption(StreamInput in) throws IOException {
private static final ObjectParser<Entry, Void> 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) {
Expand Down

0 comments on commit e889ea8

Please sign in to comment.