diff --git a/modules/lang-expression/build.gradle b/modules/lang-expression/build.gradle index 9e3943a32b2..2fd6e53effa 100644 --- a/modules/lang-expression/build.gradle +++ b/modules/lang-expression/build.gradle @@ -35,6 +35,3 @@ dependencyLicenses { mapping from: /asm-.*/, to: 'asm' } -compileJava.options.compilerArgs << '-Xlint:-rawtypes' -compileTestJava.options.compilerArgs << '-Xlint:-rawtypes' - diff --git a/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/CountMethodValueSource.java b/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/CountMethodValueSource.java index c50aa4da289..043a11eebad 100644 --- a/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/CountMethodValueSource.java +++ b/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/CountMethodValueSource.java @@ -19,6 +19,10 @@ package org.elasticsearch.script.expression; +import java.io.IOException; +import java.util.Map; +import java.util.Objects; + import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; @@ -26,10 +30,6 @@ import org.elasticsearch.index.fielddata.AtomicFieldData; import org.elasticsearch.index.fielddata.AtomicNumericFieldData; import org.elasticsearch.index.fielddata.IndexFieldData; -import java.io.IOException; -import java.util.Map; -import java.util.Objects; - /** * A ValueSource to create FunctionValues to get the count of the number of values in a field for a document. */ @@ -43,6 +43,7 @@ public class CountMethodValueSource extends ValueSource { } @Override + @SuppressWarnings("rawtypes") // ValueSource uses a rawtype public FunctionValues getValues(Map context, LeafReaderContext leaf) throws IOException { AtomicFieldData leafData = fieldData.load(leaf); assert(leafData instanceof AtomicNumericFieldData); diff --git a/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/DateMethodValueSource.java b/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/DateMethodValueSource.java index 9efeed54ff9..e6c9dcddc78 100644 --- a/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/DateMethodValueSource.java +++ b/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/DateMethodValueSource.java @@ -19,6 +19,10 @@ package org.elasticsearch.script.expression; +import java.io.IOException; +import java.util.Map; +import java.util.Objects; + import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.queries.function.FunctionValues; import org.elasticsearch.index.fielddata.AtomicFieldData; @@ -26,10 +30,6 @@ import org.elasticsearch.index.fielddata.AtomicNumericFieldData; import org.elasticsearch.index.fielddata.IndexFieldData; import org.elasticsearch.search.MultiValueMode; -import java.io.IOException; -import java.util.Map; -import java.util.Objects; - class DateMethodValueSource extends FieldDataValueSource { protected final String methodName; @@ -45,6 +45,7 @@ class DateMethodValueSource extends FieldDataValueSource { } @Override + @SuppressWarnings("rawtypes") // ValueSource uses a rawtype public FunctionValues getValues(Map context, LeafReaderContext leaf) throws IOException { AtomicFieldData leafData = fieldData.load(leaf); assert(leafData instanceof AtomicNumericFieldData); diff --git a/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/FieldDataValueSource.java b/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/FieldDataValueSource.java index 708cd0af152..ae84a5cbfe7 100644 --- a/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/FieldDataValueSource.java +++ b/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/FieldDataValueSource.java @@ -19,6 +19,10 @@ package org.elasticsearch.script.expression; +import java.io.IOException; +import java.util.Map; +import java.util.Objects; + import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; @@ -27,10 +31,6 @@ import org.elasticsearch.index.fielddata.AtomicNumericFieldData; import org.elasticsearch.index.fielddata.IndexFieldData; import org.elasticsearch.search.MultiValueMode; -import java.io.IOException; -import java.util.Map; -import java.util.Objects; - /** * A {@link ValueSource} wrapper for field data. */ @@ -67,6 +67,7 @@ class FieldDataValueSource extends ValueSource { } @Override + @SuppressWarnings("rawtypes") // ValueSource uses a rawtype public FunctionValues getValues(Map context, LeafReaderContext leaf) throws IOException { AtomicFieldData leafData = fieldData.load(leaf); assert(leafData instanceof AtomicNumericFieldData); diff --git a/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ReplaceableConstValueSource.java b/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ReplaceableConstValueSource.java index c9bcc239f28..bb05ef2325d 100644 --- a/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ReplaceableConstValueSource.java +++ b/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ReplaceableConstValueSource.java @@ -19,13 +19,13 @@ package org.elasticsearch.script.expression; +import java.io.IOException; +import java.util.Map; + import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; -import java.io.IOException; -import java.util.Map; - /** * A {@link ValueSource} which has a stub {@link FunctionValues} that holds a dynamically replaceable constant double. */ @@ -37,6 +37,7 @@ class ReplaceableConstValueSource extends ValueSource { } @Override + @SuppressWarnings("rawtypes") // ValueSource uses a rawtype public FunctionValues getValues(Map map, LeafReaderContext atomicReaderContext) throws IOException { return fv; } diff --git a/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/MoreExpressionTests.java b/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/MoreExpressionTests.java index b4c0106abbe..a866f338e29 100644 --- a/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/MoreExpressionTests.java +++ b/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/MoreExpressionTests.java @@ -19,6 +19,12 @@ package org.elasticsearch.script.expression; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.apache.lucene.expressions.Expression; import org.apache.lucene.expressions.js.JavascriptCompiler; import org.elasticsearch.action.search.SearchPhaseExecutionException; @@ -47,12 +53,6 @@ import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.hamcrest.ElasticsearchAssertions; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import static org.elasticsearch.search.aggregations.AggregationBuilders.histogram; import static org.elasticsearch.search.aggregations.AggregationBuilders.sum; import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilders.bucketScript; @@ -121,7 +121,7 @@ public class MoreExpressionTests extends ESIntegTestCase { client().prepareIndex("test", "doc", "1").setSource("text", "hello goodbye"), client().prepareIndex("test", "doc", "2").setSource("text", "hello hello hello goodbye"), client().prepareIndex("test", "doc", "3").setSource("text", "hello hello goodebye")); - ScoreFunctionBuilder score = ScoreFunctionBuilders.scriptFunction(new Script("1 / _score", ScriptType.INLINE, "expression", null)); + ScoreFunctionBuilder score = ScoreFunctionBuilders.scriptFunction(new Script("1 / _score", ScriptType.INLINE, "expression", null)); SearchRequestBuilder req = client().prepareSearch().setIndices("test"); req.setQuery(QueryBuilders.functionScoreQuery(QueryBuilders.termQuery("text", "hello"), score).boostMode(CombineFunction.REPLACE)); req.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); // make sure DF is consistent diff --git a/plugins/analysis-phonetic/build.gradle b/plugins/analysis-phonetic/build.gradle index 13898be05a9..61c4fdbd583 100644 --- a/plugins/analysis-phonetic/build.gradle +++ b/plugins/analysis-phonetic/build.gradle @@ -30,6 +30,3 @@ dependencies { dependencyLicenses { mapping from: /lucene-.*/, to: 'lucene' } - -compileJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked" - diff --git a/plugins/analysis-phonetic/src/main/java/org/elasticsearch/index/analysis/PhoneticTokenFilterFactory.java b/plugins/analysis-phonetic/src/main/java/org/elasticsearch/index/analysis/PhoneticTokenFilterFactory.java index 9374410765d..e33f1f1e7e2 100644 --- a/plugins/analysis-phonetic/src/main/java/org/elasticsearch/index/analysis/PhoneticTokenFilterFactory.java +++ b/plugins/analysis-phonetic/src/main/java/org/elasticsearch/index/analysis/PhoneticTokenFilterFactory.java @@ -19,6 +19,9 @@ package org.elasticsearch.index.analysis; +import java.util.Arrays; +import java.util.HashSet; + import org.apache.commons.codec.Encoder; import org.apache.commons.codec.language.Caverphone1; import org.apache.commons.codec.language.Caverphone2; @@ -43,9 +46,6 @@ import org.elasticsearch.index.analysis.phonetic.HaasePhonetik; import org.elasticsearch.index.analysis.phonetic.KoelnerPhonetik; import org.elasticsearch.index.analysis.phonetic.Nysiis; -import java.util.Arrays; -import java.util.HashSet; - /** * */ @@ -122,7 +122,7 @@ public class PhoneticTokenFilterFactory extends AbstractTokenFilterFactory { if (encoder == null) { if (ruletype != null && nametype != null) { if (languageset != null) { - final LanguageSet languages = LanguageSet.from(new HashSet(Arrays.asList(languageset))); + final LanguageSet languages = LanguageSet.from(new HashSet<>(Arrays.asList(languageset))); return new BeiderMorseFilter(tokenStream, new PhoneticEngine(nametype, ruletype, true), languages); } return new BeiderMorseFilter(tokenStream, new PhoneticEngine(nametype, ruletype, true)); diff --git a/plugins/analysis-phonetic/src/main/java/org/elasticsearch/index/analysis/phonetic/KoelnerPhonetik.java b/plugins/analysis-phonetic/src/main/java/org/elasticsearch/index/analysis/phonetic/KoelnerPhonetik.java index 57195062cdd..3c658191524 100644 --- a/plugins/analysis-phonetic/src/main/java/org/elasticsearch/index/analysis/phonetic/KoelnerPhonetik.java +++ b/plugins/analysis-phonetic/src/main/java/org/elasticsearch/index/analysis/phonetic/KoelnerPhonetik.java @@ -19,9 +19,6 @@ package org.elasticsearch.index.analysis.phonetic; -import org.apache.commons.codec.EncoderException; -import org.apache.commons.codec.StringEncoder; - import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; @@ -31,6 +28,9 @@ import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.codec.EncoderException; +import org.apache.commons.codec.StringEncoder; + /** * Kölner Phonetik * @@ -49,13 +49,13 @@ public class KoelnerPhonetik implements StringEncoder { private static final String[] POSTEL_VARIATIONS_REPLACEMENTS = {"OWN", "AUN", "RW", "RB", "RSK", "WSK"}; private Pattern[] variationsPatterns; private boolean primary = false; - private final Set csz = new HashSet(Arrays.asList( + private final Set csz = new HashSet<>(Arrays.asList( 'C', 'S', 'Z')); - private final Set ckq = new HashSet(Arrays.asList( + private final Set ckq = new HashSet<>(Arrays.asList( 'C', 'K', 'Q')); - private final Set aouhkxq = new HashSet(Arrays.asList( + private final Set aouhkxq = new HashSet<>(Arrays.asList( 'A', 'O', 'U', 'H', 'K', 'X', 'Q')); - private final Set ahkloqrux = new HashSet(Arrays.asList( + private final Set ahkloqrux = new HashSet<>(Arrays.asList( 'A', 'H', 'K', 'L', 'O', 'Q', 'R', 'U', 'X')); /** @@ -139,10 +139,10 @@ public class KoelnerPhonetik implements StringEncoder { private List partition(String str) { String primaryForm = str; - List parts = new ArrayList(); + List parts = new ArrayList<>(); parts.add(primaryForm.replaceAll("[^\\p{L}\\p{N}]", "")); if (!primary) { - List tmpParts = new ArrayList(); + List tmpParts = new ArrayList<>(); tmpParts.addAll((Arrays.asList(str.split("[\\p{Z}\\p{C}\\p{P}]")))); int numberOfParts = tmpParts.size(); while (tmpParts.size() > 0) { @@ -156,9 +156,9 @@ public class KoelnerPhonetik implements StringEncoder { tmpParts.remove(0); } } - List variations = new ArrayList(); + List variations = new ArrayList<>(); for (int i = 0; i < parts.size(); i++) { - List variation = getVariations(parts.get(i)); + List variation = getVariations(parts.get(i)); if (variation != null) { variations.addAll(variation); } @@ -166,9 +166,9 @@ public class KoelnerPhonetik implements StringEncoder { return variations; } - private List getVariations(String str) { + private List getVariations(String str) { int position = 0; - List variations = new ArrayList(); + List variations = new ArrayList<>(); variations.add(""); while (position < str.length()) { int i = 0; @@ -182,7 +182,7 @@ public class KoelnerPhonetik implements StringEncoder { } if (substPos >= position) { i--; - List varNew = new ArrayList(); + List varNew = new ArrayList<>(); String prevPart = str.substring(position, substPos); for (int ii = 0; ii < variations.size(); ii++) { String tmp = variations.get(ii); diff --git a/plugins/jvm-example/build.gradle b/plugins/jvm-example/build.gradle index f0dd69ff8c4..c5828d9c86d 100644 --- a/plugins/jvm-example/build.gradle +++ b/plugins/jvm-example/build.gradle @@ -25,8 +25,6 @@ esplugin { // no unit tests test.enabled = false -compileJava.options.compilerArgs << "-Xlint:-rawtypes" - configurations { exampleFixture } diff --git a/plugins/jvm-example/src/main/java/org/elasticsearch/plugin/example/JvmExamplePlugin.java b/plugins/jvm-example/src/main/java/org/elasticsearch/plugin/example/JvmExamplePlugin.java index c1bcc65bfe2..0c0e71dc1c0 100644 --- a/plugins/jvm-example/src/main/java/org/elasticsearch/plugin/example/JvmExamplePlugin.java +++ b/plugins/jvm-example/src/main/java/org/elasticsearch/plugin/example/JvmExamplePlugin.java @@ -19,6 +19,10 @@ package org.elasticsearch.plugin.example; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; + import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Module; @@ -28,10 +32,6 @@ import org.elasticsearch.plugins.Plugin; import org.elasticsearch.repositories.RepositoriesModule; import org.elasticsearch.rest.action.cat.AbstractCatAction; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; - /** * Example of a plugin. */ @@ -59,6 +59,7 @@ public class JvmExamplePlugin extends Plugin { } @Override + @SuppressWarnings("rawtypes") // Plugin use a rawtype public Collection> nodeServices() { Collection> services = new ArrayList<>(); return services; diff --git a/plugins/lang-javascript/build.gradle b/plugins/lang-javascript/build.gradle index ead459f29d1..cce5869341e 100644 --- a/plugins/lang-javascript/build.gradle +++ b/plugins/lang-javascript/build.gradle @@ -26,13 +26,9 @@ dependencies { compile 'org.mozilla:rhino:1.7.7' } -compileJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked" -compileTestJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked" - integTest { cluster { systemProperty 'es.script.inline', 'on' systemProperty 'es.script.indexed', 'on' } } - diff --git a/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java b/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java index eca1265766d..14124551e76 100644 --- a/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java +++ b/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java @@ -19,6 +19,18 @@ package org.elasticsearch.script.javascript; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.security.AccessControlContext; +import java.security.AccessController; +import java.security.CodeSource; +import java.security.PrivilegedAction; +import java.security.cert.Certificate; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; + import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.search.Scorer; import org.elasticsearch.SpecialPermission; @@ -49,18 +61,6 @@ import org.mozilla.javascript.ScriptableObject; import org.mozilla.javascript.SecurityController; import org.mozilla.javascript.WrapFactory; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.security.AccessControlContext; -import java.security.AccessController; -import java.security.CodeSource; -import java.security.PrivilegedAction; -import java.security.cert.Certificate; -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicLong; - /** * */ @@ -348,12 +348,14 @@ public class JavaScriptScriptEngineService extends AbstractComponent implements setJavaPrimitiveWrap(false); // RingoJS does that..., claims its annoying... } - public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, Object javaObject, Class staticType) { + @Override + @SuppressWarnings("unchecked") + public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, Object javaObject, Class staticType) { if (javaObject instanceof Map) { - return NativeMap.wrap(scope, (Map) javaObject); + return NativeMap.wrap(scope, (Map) javaObject); } if (javaObject instanceof List) { - return NativeList.wrap(scope, (List) javaObject, staticType); + return NativeList.wrap(scope, (List) javaObject, staticType); } return super.wrapAsJavaObject(cx, scope, javaObject, staticType); } diff --git a/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/NativeMap.java b/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/NativeMap.java index 1dbf3454900..ef9be14b0dd 100644 --- a/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/NativeMap.java +++ b/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/NativeMap.java @@ -19,12 +19,12 @@ package org.elasticsearch.script.javascript.support; -import org.mozilla.javascript.Scriptable; -import org.mozilla.javascript.Wrapper; - import java.util.Iterator; import java.util.Map; +import org.mozilla.javascript.Scriptable; +import org.mozilla.javascript.Wrapper; + /** * Wrapper for exposing maps in Rhino scripts. * @@ -55,26 +55,17 @@ public class NativeMap implements Scriptable, Wrapper { this.map = map; } - /* (non-Javadoc) - * @see org.mozilla.javascript.Wrapper#unwrap() - */ - + @Override public Object unwrap() { return map; } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getClassName() - */ - + @Override public String getClassName() { return "NativeMap"; } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#get(java.lang.String, org.mozilla.javascript.Scriptable) - */ - + @Override public Object get(String name, Scriptable start) { // get the property from the underlying QName map if ("length".equals(name)) { @@ -84,69 +75,47 @@ public class NativeMap implements Scriptable, Wrapper { } } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#get(int, org.mozilla.javascript.Scriptable) - */ - + @Override public Object get(int index, Scriptable start) { Object value = null; int i = 0; - Iterator itrValues = map.values().iterator(); + Iterator itrValues = map.values().iterator(); while (i++ <= index && itrValues.hasNext()) { value = itrValues.next(); } return value; } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#has(java.lang.String, org.mozilla.javascript.Scriptable) - */ - + @Override public boolean has(String name, Scriptable start) { // locate the property in the underlying map return map.containsKey(name); } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#has(int, org.mozilla.javascript.Scriptable) - */ - + @Override public boolean has(int index, Scriptable start) { return (index >= 0 && map.values().size() > index); } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#put(java.lang.String, org.mozilla.javascript.Scriptable, java.lang.Object) - */ - - @SuppressWarnings("unchecked") + @Override public void put(String name, Scriptable start, Object value) { map.put(name, value); } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#put(int, org.mozilla.javascript.Scriptable, java.lang.Object) - */ - + @Override public void put(int index, Scriptable start, Object value) { // TODO: implement? } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#delete(java.lang.String) - */ - + @Override public void delete(String name) { map.remove(name); } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#delete(int) - */ - + @Override public void delete(int index) { int i = 0; - Iterator itrKeys = map.keySet().iterator(); + Iterator itrKeys = map.keySet().iterator(); while (i <= index && itrKeys.hasNext()) { Object key = itrKeys.next(); if (i == index) { @@ -156,58 +125,37 @@ public class NativeMap implements Scriptable, Wrapper { } } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getPrototype() - */ - + @Override public Scriptable getPrototype() { return this.prototype; } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#setPrototype(org.mozilla.javascript.Scriptable) - */ - + @Override public void setPrototype(Scriptable prototype) { this.prototype = prototype; } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getParentScope() - */ - + @Override public Scriptable getParentScope() { return this.parentScope; } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#setParentScope(org.mozilla.javascript.Scriptable) - */ - + @Override public void setParentScope(Scriptable parent) { this.parentScope = parent; } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getIds() - */ - + @Override public Object[] getIds() { return map.keySet().toArray(); } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getDefaultValue(java.lang.Class) - */ - - public Object getDefaultValue(Class hint) { + @Override + public Object getDefaultValue(Class hint) { return null; } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#hasInstance(org.mozilla.javascript.Scriptable) - */ - + @Override public boolean hasInstance(Scriptable value) { if (!(value instanceof Wrapper)) return false; diff --git a/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptValueConverter.java b/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptValueConverter.java index a90948c1877..111d2a22b87 100644 --- a/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptValueConverter.java +++ b/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptValueConverter.java @@ -19,13 +19,6 @@ package org.elasticsearch.script.javascript.support; -import org.mozilla.javascript.Context; -import org.mozilla.javascript.IdScriptableObject; -import org.mozilla.javascript.NativeArray; -import org.mozilla.javascript.ScriptRuntime; -import org.mozilla.javascript.Scriptable; -import org.mozilla.javascript.Wrapper; - import java.util.ArrayList; import java.util.Collection; import java.util.Date; @@ -33,6 +26,13 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.mozilla.javascript.Context; +import org.mozilla.javascript.IdScriptableObject; +import org.mozilla.javascript.NativeArray; +import org.mozilla.javascript.ScriptRuntime; +import org.mozilla.javascript.Scriptable; +import org.mozilla.javascript.Wrapper; + /** * Value Converter to marshal objects between Java and Javascript. * @@ -126,6 +126,7 @@ public final class ScriptValueConverter { value = list; } else if (value instanceof Map) { // ensure each value in the Map is unwrapped (which may have been an unwrapped NativeMap!) + @SuppressWarnings("unchecked") Map map = (Map) value; Map copyMap = new HashMap(map.size()); for (Object key : map.keySet()) { @@ -157,6 +158,7 @@ public final class ScriptValueConverter { Context.getCurrentContext(), scope, TYPE_DATE, new Object[]{date.getTime()}); } else if (value instanceof Collection) { // recursively convert each value in the collection + @SuppressWarnings("unchecked") Collection collection = (Collection) value; Object[] array = new Object[collection.size()]; int index = 0; @@ -166,7 +168,9 @@ public final class ScriptValueConverter { // convert array to a native JavaScript Array value = Context.getCurrentContext().newArray(scope, array); } else if (value instanceof Map) { - value = NativeMap.wrap(scope, (Map) value); + @SuppressWarnings("unchecked") + Map map = (Map) value; + value = NativeMap.wrap(scope, map); } // simple numbers, strings and booleans are wrapped automatically by Rhino diff --git a/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptableLinkedHashMap.java b/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptableLinkedHashMap.java index 680b20a0256..f4df25f0861 100644 --- a/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptableLinkedHashMap.java +++ b/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptableLinkedHashMap.java @@ -19,12 +19,12 @@ package org.elasticsearch.script.javascript.support; -import org.mozilla.javascript.Scriptable; - import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; +import org.mozilla.javascript.Scriptable; + /** * Implementation of a Scriptable Map. This is the best choice for maps that want to represent * JavaScript associative arrays - allowing access via key and integer index. It maintains and @@ -53,6 +53,7 @@ public class ScriptableLinkedHashMap extends LinkedHashMap implement /** * @see org.mozilla.javascript.Scriptable#getClassName() */ + @Override public String getClassName() { return "ScriptableMap"; } @@ -60,6 +61,7 @@ public class ScriptableLinkedHashMap extends LinkedHashMap implement /** * @see org.mozilla.javascript.Scriptable#get(java.lang.String, org.mozilla.javascript.Scriptable) */ + @Override public Object get(String name, Scriptable start) { // get the property from the underlying QName map if ("length".equals(name)) { @@ -72,10 +74,11 @@ public class ScriptableLinkedHashMap extends LinkedHashMap implement /** * @see org.mozilla.javascript.Scriptable#get(int, org.mozilla.javascript.Scriptable) */ + @Override public Object get(int index, Scriptable start) { Object value = null; int i = 0; - Iterator itrValues = this.values().iterator(); + Iterator itrValues = this.values().iterator(); while (i++ <= index && itrValues.hasNext()) { value = itrValues.next(); } @@ -85,6 +88,7 @@ public class ScriptableLinkedHashMap extends LinkedHashMap implement /** * @see org.mozilla.javascript.Scriptable#has(java.lang.String, org.mozilla.javascript.Scriptable) */ + @Override public boolean has(String name, Scriptable start) { // locate the property in the underlying map return containsKey(name); @@ -93,6 +97,7 @@ public class ScriptableLinkedHashMap extends LinkedHashMap implement /** * @see org.mozilla.javascript.Scriptable#has(int, org.mozilla.javascript.Scriptable) */ + @Override public boolean has(int index, Scriptable start) { return (index >= 0 && this.values().size() > index); } @@ -100,6 +105,7 @@ public class ScriptableLinkedHashMap extends LinkedHashMap implement /** * @see org.mozilla.javascript.Scriptable#put(java.lang.String, org.mozilla.javascript.Scriptable, java.lang.Object) */ + @Override @SuppressWarnings("unchecked") public void put(String name, Scriptable start, Object value) { // add the property to the underlying QName map @@ -109,6 +115,7 @@ public class ScriptableLinkedHashMap extends LinkedHashMap implement /** * @see org.mozilla.javascript.Scriptable#put(int, org.mozilla.javascript.Scriptable, java.lang.Object) */ + @Override public void put(int index, Scriptable start, Object value) { // TODO: implement? } @@ -116,6 +123,7 @@ public class ScriptableLinkedHashMap extends LinkedHashMap implement /** * @see org.mozilla.javascript.Scriptable#delete(java.lang.String) */ + @Override public void delete(String name) { // remove the property from the underlying QName map remove(name); @@ -124,9 +132,10 @@ public class ScriptableLinkedHashMap extends LinkedHashMap implement /** * @see org.mozilla.javascript.Scriptable#delete(int) */ + @Override public void delete(int index) { int i = 0; - Iterator itrKeys = this.keySet().iterator(); + Iterator itrKeys = this.keySet().iterator(); while (i <= index && itrKeys.hasNext()) { Object key = itrKeys.next(); if (i == index) { @@ -139,6 +148,7 @@ public class ScriptableLinkedHashMap extends LinkedHashMap implement /** * @see org.mozilla.javascript.Scriptable#getPrototype() */ + @Override public Scriptable getPrototype() { return this.prototype; } @@ -146,6 +156,7 @@ public class ScriptableLinkedHashMap extends LinkedHashMap implement /** * @see org.mozilla.javascript.Scriptable#setPrototype(org.mozilla.javascript.Scriptable) */ + @Override public void setPrototype(Scriptable prototype) { this.prototype = prototype; } @@ -153,6 +164,7 @@ public class ScriptableLinkedHashMap extends LinkedHashMap implement /** * @see org.mozilla.javascript.Scriptable#getParentScope() */ + @Override public Scriptable getParentScope() { return this.parentScope; } @@ -160,6 +172,7 @@ public class ScriptableLinkedHashMap extends LinkedHashMap implement /** * @see org.mozilla.javascript.Scriptable#setParentScope(org.mozilla.javascript.Scriptable) */ + @Override public void setParentScope(Scriptable parent) { this.parentScope = parent; } @@ -167,6 +180,7 @@ public class ScriptableLinkedHashMap extends LinkedHashMap implement /** * @see org.mozilla.javascript.Scriptable#getIds() */ + @Override public Object[] getIds() { return keySet().toArray(); } @@ -174,13 +188,15 @@ public class ScriptableLinkedHashMap extends LinkedHashMap implement /** * @see org.mozilla.javascript.Scriptable#getDefaultValue(java.lang.Class) */ - public Object getDefaultValue(Class hint) { + @Override + public Object getDefaultValue(Class hint) { return null; } /** * @see org.mozilla.javascript.Scriptable#hasInstance(org.mozilla.javascript.Scriptable) */ + @Override public boolean hasInstance(Scriptable instance) { return instance instanceof ScriptableLinkedHashMap; } diff --git a/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptableWrappedMap.java b/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptableWrappedMap.java index 9ff1f61c8d5..1aa2326482a 100644 --- a/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptableWrappedMap.java +++ b/plugins/lang-javascript/src/main/java/org/elasticsearch/script/javascript/support/ScriptableWrappedMap.java @@ -19,14 +19,14 @@ package org.elasticsearch.script.javascript.support; -import org.mozilla.javascript.Scriptable; -import org.mozilla.javascript.Wrapper; - import java.util.Collection; import java.util.Iterator; import java.util.Map; import java.util.Set; +import org.mozilla.javascript.Scriptable; +import org.mozilla.javascript.Wrapper; + /** * Implementation of a Scriptable Map. This is the best choice where you want values to be * persisted directly to an underlying map supplied on construction. The class automatically @@ -37,8 +37,8 @@ import java.util.Set; * * */ -public class ScriptableWrappedMap implements ScriptableMap, Wrapper { - private Map map; +public class ScriptableWrappedMap implements ScriptableMap, Wrapper { + private Map map; private Scriptable parentScope; private Scriptable prototype; @@ -54,38 +54,29 @@ public class ScriptableWrappedMap implements ScriptableMap, Wrapper { /** * Construct */ - public ScriptableWrappedMap(Map map) { + public ScriptableWrappedMap(Map map) { this.map = map; } /** * Construct */ - public ScriptableWrappedMap(Scriptable scope, Map map) { + public ScriptableWrappedMap(Scriptable scope, Map map) { this.parentScope = scope; this.map = map; } - /* (non-Javadoc) - * @see org.mozilla.javascript.Wrapper#unwrap() - */ - + @Override public Object unwrap() { return map; } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getClassName() - */ - + @Override public String getClassName() { return "ScriptableWrappedMap"; } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#get(java.lang.String, org.mozilla.javascript.Scriptable) - */ - + @Override public Object get(String name, Scriptable start) { // get the property from the underlying QName map if ("length".equals(name)) { @@ -95,69 +86,47 @@ public class ScriptableWrappedMap implements ScriptableMap, Wrapper { } } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#get(int, org.mozilla.javascript.Scriptable) - */ - + @Override public Object get(int index, Scriptable start) { Object value = null; int i = 0; - Iterator itrValues = map.values().iterator(); + Iterator itrValues = map.values().iterator(); while (i++ <= index && itrValues.hasNext()) { value = itrValues.next(); } return ScriptValueConverter.wrapValue(this.parentScope != null ? this.parentScope : start, value); } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#has(java.lang.String, org.mozilla.javascript.Scriptable) - */ - + @Override public boolean has(String name, Scriptable start) { // locate the property in the underlying map return map.containsKey(name); } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#has(int, org.mozilla.javascript.Scriptable) - */ - + @Override public boolean has(int index, Scriptable start) { return (index >= 0 && map.values().size() > index); } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#put(java.lang.String, org.mozilla.javascript.Scriptable, java.lang.Object) - */ - - @SuppressWarnings("unchecked") + @Override public void put(String name, Scriptable start, Object value) { map.put(name, ScriptValueConverter.unwrapValue(value)); } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#put(int, org.mozilla.javascript.Scriptable, java.lang.Object) - */ - + @Override public void put(int index, Scriptable start, Object value) { // TODO: implement? } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#delete(java.lang.String) - */ - + @Override public void delete(String name) { map.remove(name); } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#delete(int) - */ - + @Override public void delete(int index) { int i = 0; - Iterator itrKeys = map.keySet().iterator(); + Iterator itrKeys = map.keySet().iterator(); while (i <= index && itrKeys.hasNext()) { Object key = itrKeys.next(); if (i == index) { @@ -167,58 +136,37 @@ public class ScriptableWrappedMap implements ScriptableMap, Wrapper { } } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getPrototype() - */ - + @Override public Scriptable getPrototype() { return this.prototype; } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#setPrototype(org.mozilla.javascript.Scriptable) - */ - + @Override public void setPrototype(Scriptable prototype) { this.prototype = prototype; } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getParentScope() - */ - + @Override public Scriptable getParentScope() { return this.parentScope; } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#setParentScope(org.mozilla.javascript.Scriptable) - */ - + @Override public void setParentScope(Scriptable parent) { this.parentScope = parent; } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getIds() - */ - + @Override public Object[] getIds() { return map.keySet().toArray(); } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#getDefaultValue(java.lang.Class) - */ - - public Object getDefaultValue(Class hint) { + @Override + public Object getDefaultValue(Class hint) { return null; } - /* (non-Javadoc) - * @see org.mozilla.javascript.Scriptable#hasInstance(org.mozilla.javascript.Scriptable) - */ - + @Override public boolean hasInstance(Scriptable value) { if (!(value instanceof Wrapper)) return false; @@ -226,106 +174,66 @@ public class ScriptableWrappedMap implements ScriptableMap, Wrapper { return Map.class.isInstance(instance); } - /* (non-Javadoc) - * @see java.util.Map#clear() - */ - + @Override public void clear() { this.map.clear(); } - /* (non-Javadoc) - * @see java.util.Map#containsKey(java.lang.Object) - */ - + @Override public boolean containsKey(Object key) { return this.map.containsKey(key); } - /* (non-Javadoc) - * @see java.util.Map#containsValue(java.lang.Object) - */ - + @Override public boolean containsValue(Object value) { return this.map.containsValue(value); } - /* (non-Javadoc) - * @see java.util.Map#entrySet() - */ - - public Set entrySet() { + @Override + public Set> entrySet() { return this.map.entrySet(); } - /* (non-Javadoc) - * @see java.util.Map#get(java.lang.Object) - */ - + @Override public Object get(Object key) { return this.map.get(key); } - /* (non-Javadoc) - * @see java.util.Map#isEmpty() - */ - + @Override public boolean isEmpty() { return (this.map.size() == 0); } - /* (non-Javadoc) - * @see java.util.Map#keySet() - */ - - public Set keySet() { + @Override + public Set keySet() { return this.map.keySet(); } - /* (non-Javadoc) - * @see java.util.Map#put(java.lang.Object, java.lang.Object) - */ - + @Override public Object put(Object key, Object value) { return this.map.put(key, value); } - /* (non-Javadoc) - * @see java.util.Map#putAll(java.util.Map) - */ - - public void putAll(Map t) { + @Override + public void putAll(Map t) { this.map.putAll(t); } - /* (non-Javadoc) - * @see java.util.Map#remove(java.lang.Object) - */ - + @Override public Object remove(Object key) { return this.map.remove(key); } - /* (non-Javadoc) - * @see java.util.Map#size() - */ - + @Override public int size() { return this.map.size(); } - /* (non-Javadoc) - * @see java.util.Map#values() - */ - - public Collection values() { + @Override + public Collection values() { return this.map.values(); } - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override public String toString() { return (this.map != null ? this.map.toString() : super.toString()); diff --git a/plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java b/plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java index 9d8357bb582..5ed2e7e4cb8 100644 --- a/plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java +++ b/plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java @@ -19,6 +19,12 @@ package org.elasticsearch.script.javascript; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.script.CompiledScript; @@ -28,12 +34,6 @@ import org.elasticsearch.test.ESTestCase; import org.junit.After; import org.junit.Before; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; @@ -59,6 +59,7 @@ public class JavaScriptScriptEngineTests extends ESTestCase { assertThat(((Number) o).intValue(), equalTo(3)); } + @SuppressWarnings("unchecked") public void testMapAccess() { Map vars = new HashMap(); @@ -75,15 +76,17 @@ public class JavaScriptScriptEngineTests extends ESTestCase { assertThat(((String) o), equalTo("2")); } + @SuppressWarnings("unchecked") public void testJavaScriptObjectToMap() { Map vars = new HashMap(); Object o = se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "testJavaScriptObjectToMap", "js", se.compile("var obj1 = {}; obj1.prop1 = 'value1'; obj1.obj2 = {}; obj1.obj2.prop2 = 'value2'; obj1", Collections.emptyMap())), vars).run(); - Map obj1 = (Map) o; + Map obj1 = (Map) o; assertThat((String) obj1.get("prop1"), equalTo("value1")); assertThat((String) ((Map) obj1.get("obj2")).get("prop2"), equalTo("value2")); } + @SuppressWarnings("unchecked") public void testJavaScriptObjectMapInter() { Map vars = new HashMap(); Map ctx = new HashMap(); @@ -102,6 +105,7 @@ public class JavaScriptScriptEngineTests extends ESTestCase { assertThat((String) ((Map) ctx.get("obj2")).get("prop2"), equalTo("value2")); } + @SuppressWarnings("unchecked") public void testJavaScriptInnerArrayCreation() { Map ctx = new HashMap(); Map doc = new HashMap(); @@ -115,9 +119,10 @@ public class JavaScriptScriptEngineTests extends ESTestCase { Map unwrap = (Map) script.unwrap(ctx); - assertThat(((Map) unwrap.get("doc")).get("field1"), instanceOf(List.class)); + assertThat(((Map) unwrap.get("doc")).get("field1"), instanceOf(List.class)); } + @SuppressWarnings("unchecked") public void testAccessListInScript() { Map vars = new HashMap(); Map obj2 = MapBuilder.newMapBuilder().put("prop2", "value2").map(); diff --git a/plugins/lang-python/build.gradle b/plugins/lang-python/build.gradle index 103a15784ea..dde9a63bad1 100644 --- a/plugins/lang-python/build.gradle +++ b/plugins/lang-python/build.gradle @@ -26,9 +26,6 @@ dependencies { compile 'org.python:jython-standalone:2.7.0' } -compileJava.options.compilerArgs << "-Xlint:-unchecked" -compileTestJava.options.compilerArgs << "-Xlint:-unchecked" - integTest { cluster { systemProperty 'es.script.inline', 'on' diff --git a/plugins/lang-python/src/test/java/org/elasticsearch/script/python/PythonScriptEngineTests.java b/plugins/lang-python/src/test/java/org/elasticsearch/script/python/PythonScriptEngineTests.java index a0bfab43c54..fd876d8cee8 100644 --- a/plugins/lang-python/src/test/java/org/elasticsearch/script/python/PythonScriptEngineTests.java +++ b/plugins/lang-python/src/test/java/org/elasticsearch/script/python/PythonScriptEngineTests.java @@ -19,6 +19,11 @@ package org.elasticsearch.script.python; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.script.CompiledScript; @@ -28,11 +33,6 @@ import org.elasticsearch.test.ESTestCase; import org.junit.After; import org.junit.Before; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; @@ -58,6 +58,7 @@ public class PythonScriptEngineTests extends ESTestCase { assertThat(((Number) o).intValue(), equalTo(3)); } + @SuppressWarnings("unchecked") public void testMapAccess() { Map vars = new HashMap(); @@ -74,6 +75,7 @@ public class PythonScriptEngineTests extends ESTestCase { assertThat(((String) o), equalTo("2")); } + @SuppressWarnings("unchecked") public void testObjectMapInter() { Map vars = new HashMap(); Map ctx = new HashMap(); @@ -92,6 +94,7 @@ public class PythonScriptEngineTests extends ESTestCase { assertThat((String) ((Map) ctx.get("obj2")).get("prop2"), equalTo("value2")); } + @SuppressWarnings("unchecked") public void testAccessListInScript() { Map vars = new HashMap(); Map obj2 = MapBuilder.newMapBuilder().put("prop2", "value2").map(); diff --git a/plugins/mapper-murmur3/build.gradle b/plugins/mapper-murmur3/build.gradle index ca93c118487..5b985d9138f 100644 --- a/plugins/mapper-murmur3/build.gradle +++ b/plugins/mapper-murmur3/build.gradle @@ -21,5 +21,3 @@ esplugin { description 'The Mapper Murmur3 plugin allows to compute hashes of a field\'s values at index-time and to store them in the index.' classname 'org.elasticsearch.plugin.mapper.MapperMurmur3Plugin' } - -compileJava.options.compilerArgs << "-Xlint:-rawtypes" diff --git a/plugins/mapper-murmur3/src/main/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapper.java b/plugins/mapper-murmur3/src/main/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapper.java index 03b00d2ac39..ce78c75d783 100644 --- a/plugins/mapper-murmur3/src/main/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapper.java +++ b/plugins/mapper-murmur3/src/main/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapper.java @@ -19,6 +19,10 @@ package org.elasticsearch.index.mapper.murmur3; +import java.io.IOException; +import java.util.List; +import java.util.Map; + import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexOptions; import org.apache.lucene.util.BytesRef; @@ -35,10 +39,6 @@ import org.elasticsearch.index.mapper.ParseContext; import org.elasticsearch.index.mapper.core.LongFieldMapper; import org.elasticsearch.index.mapper.core.NumberFieldMapper; -import java.io.IOException; -import java.util.List; -import java.util.Map; - import static org.elasticsearch.index.mapper.core.TypeParsers.parseNumberField; public class Murmur3FieldMapper extends LongFieldMapper { @@ -93,8 +93,7 @@ public class Murmur3FieldMapper extends LongFieldMapper { public static class TypeParser implements Mapper.TypeParser { @Override - @SuppressWarnings("unchecked") - public Mapper.Builder parse(String name, Map node, ParserContext parserContext) throws MapperParsingException { + public Mapper.Builder parse(String name, Map node, ParserContext parserContext) throws MapperParsingException { Builder builder = new Builder(name); // tweaking these settings is no longer allowed, the entire purpose of murmur3 fields is to store a hash