diff --git a/.idea/libraries/jackson.xml b/.idea/libraries/jackson.xml index c17528f9b19..b28077d00a3 100644 --- a/.idea/libraries/jackson.xml +++ b/.idea/libraries/jackson.xml @@ -5,6 +5,11 @@ - + + + + + + \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonDocumentMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonDocumentMapper.java index 95cf195bb1c..a65a80ae65f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonDocumentMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonDocumentMapper.java @@ -252,8 +252,9 @@ public class JsonDocumentMapper implements DocumentMapper { } type = this.type; + JsonParser jp = null; try { - JsonParser jp = jsonFactory.createJsonParser(new FastStringReader(source)); + jp = jsonFactory.createJsonParser(new FastStringReader(source)); jsonContext.reset(jp, new Document(), type, source); // will result in JsonToken.START_OBJECT @@ -301,6 +302,14 @@ public class JsonDocumentMapper implements DocumentMapper { } } catch (IOException e) { throw new MapperParsingException("Failed to parse", e); + } finally { + if (jp != null) { + try { + jp.close(); + } catch (IOException e) { + // ignore + } + } } return new ParsedDocument(jsonContext.uid(), jsonContext.id(), jsonContext.type(), jsonContext.doc(), source); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/JsonIndexQueryParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/JsonIndexQueryParser.java index 04ccc3740b6..4d6624813ce 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/JsonIndexQueryParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/JsonIndexQueryParser.java @@ -123,12 +123,22 @@ public class JsonIndexQueryParser extends AbstractIndexComponent implements Inde } @Override public Query parse(String source) throws QueryParsingException { + JsonParser jp = null; try { - return parse(cache.get(), source, jsonFactory.createJsonParser(new FastStringReader(source))); + jp = jsonFactory.createJsonParser(new FastStringReader(source)); + return parse(cache.get(), source, jp); } catch (QueryParsingException e) { throw e; } catch (Exception e) { throw new QueryParsingException(index, "Failed to parse [" + source + "]", e); + } finally { + if (jp != null) { + try { + jp.close(); + } catch (IOException e) { + // ignore + } + } } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/json/JsonBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/json/JsonBuilder.java index e5ab9f13e9c..536d97146d6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/json/JsonBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/util/json/JsonBuilder.java @@ -360,7 +360,11 @@ public class JsonBuilder { return result; } - public void close() throws IOException { - generator.close(); + public void close() { + try { + generator.close(); + } catch (IOException e) { + // ignore + } } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/loader/JsonSettingsLoader.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/loader/JsonSettingsLoader.java index 421c8a0d5a6..2c37d1685e2 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/loader/JsonSettingsLoader.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/util/settings/loader/JsonSettingsLoader.java @@ -43,7 +43,11 @@ public class JsonSettingsLoader implements SettingsLoader { @Override public Map load(String source) throws IOException { JsonParser jp = jsonFactory.createJsonParser(new FastStringReader(source)); - return load(jp); + try { + return load(jp); + } finally { + jp.close(); + } } public Map load(JsonParser jp) throws IOException {