diff --git a/all-signatures.txt b/all-signatures.txt new file mode 100644 index 00000000000..5f13cea4af7 --- /dev/null +++ b/all-signatures.txt @@ -0,0 +1,3 @@ +@defaultMessage Convert to URI +java.net.URL#getPath() +java.net.URL#getFile() diff --git a/core-signatures.txt b/core-signatures.txt new file mode 100644 index 00000000000..f14d5415a34 --- /dev/null +++ b/core-signatures.txt @@ -0,0 +1,60 @@ +@defaultMessage spawns threads with vague names; use a custom thread factory and name threads so that you can tell (by its name) which executor it is associated with + +java.util.concurrent.Executors#newFixedThreadPool(int) +java.util.concurrent.Executors#newSingleThreadExecutor() +java.util.concurrent.Executors#newCachedThreadPool() +java.util.concurrent.Executors#newSingleThreadScheduledExecutor() +java.util.concurrent.Executors#newScheduledThreadPool(int) +java.util.concurrent.Executors#defaultThreadFactory() +java.util.concurrent.Executors#privilegedThreadFactory() + +java.lang.Character#codePointBefore(char[],int) @ Implicit start offset is error-prone when the char[] is a buffer and the first chars are random chars +java.lang.Character#codePointAt(char[],int) @ Implicit end offset is error-prone when the char[] is a buffer and the last chars are random chars + +java.io.StringReader#(java.lang.String) @ Use FastStringReader instead + +@defaultMessage Reference management is tricky, leave it to SearcherManager +org.apache.lucene.index.IndexReader#decRef() +org.apache.lucene.index.IndexReader#incRef() +org.apache.lucene.index.IndexReader#tryIncRef() + +@defaultMessage QueryWrapperFilter is cachable by default - use Queries#wrap instead +org.apache.lucene.search.QueryWrapperFilter#(org.apache.lucene.search.Query) + +@defaultMessage Because the filtercache doesn't take deletes into account FilteredQuery can't be used - use XFilteredQuery instead +org.apache.lucene.search.FilteredQuery#(org.apache.lucene.search.Query,org.apache.lucene.search.Filter) +org.apache.lucene.search.FilteredQuery#(org.apache.lucene.search.Query,org.apache.lucene.search.Filter,org.apache.lucene.search.FilteredQuery$FilterStrategy) + +@defaultMessage Pass the precision step from the mappings explicitly instead +org.apache.lucene.search.NumericRangeQuery#newDoubleRange(java.lang.String,java.lang.Double,java.lang.Double,boolean,boolean) +org.apache.lucene.search.NumericRangeQuery#newFloatRange(java.lang.String,java.lang.Float,java.lang.Float,boolean,boolean) +org.apache.lucene.search.NumericRangeQuery#newIntRange(java.lang.String,java.lang.Integer,java.lang.Integer,boolean,boolean) +org.apache.lucene.search.NumericRangeQuery#newLongRange(java.lang.String,java.lang.Long,java.lang.Long,boolean,boolean) +org.apache.lucene.search.NumericRangeFilter#newDoubleRange(java.lang.String,java.lang.Double,java.lang.Double,boolean,boolean) +org.apache.lucene.search.NumericRangeFilter#newFloatRange(java.lang.String,java.lang.Float,java.lang.Float,boolean,boolean) +org.apache.lucene.search.NumericRangeFilter#newIntRange(java.lang.String,java.lang.Integer,java.lang.Integer,boolean,boolean) +org.apache.lucene.search.NumericRangeFilter#newLongRange(java.lang.String,java.lang.Long,java.lang.Long,boolean,boolean) + +@defaultMessage Only use wait / notify when really needed try to use concurrency primitives, latches or callbacks instead. +java.lang.Object#wait() +java.lang.Object#wait(long) +java.lang.Object#wait(long,int) +java.lang.Object#notify() +java.lang.Object#notifyAll() + +@defaultMessage Beware of the behavior of this method on MIN_VALUE +java.lang.Math#abs(int) +java.lang.Math#abs(long) + +@defaultMessage Please do not try to stop the world +java.lang.System#gc() + +@defaultMessage Use Channels.* methods to write to channels. Do not write directly. +java.nio.channels.WritableByteChannel#write(java.nio.ByteBuffer) +java.nio.channels.FileChannel#write(java.nio.ByteBuffer, long) +java.nio.channels.GatheringByteChannel#write(java.nio.ByteBuffer[], int, int) +java.nio.channels.GatheringByteChannel#write(java.nio.ByteBuffer[]) +java.nio.channels.ReadableByteChannel#read(java.nio.ByteBuffer) +java.nio.channels.ScatteringByteChannel#read(java.nio.ByteBuffer[]) +java.nio.channels.ScatteringByteChannel#read(java.nio.ByteBuffer[], int, int) +java.nio.channels.FileChannel#read(java.nio.ByteBuffer, long) \ No newline at end of file diff --git a/pom.xml b/pom.xml index 0457652aed5..2b45300f2a8 100644 --- a/pom.xml +++ b/pom.xml @@ -392,7 +392,6 @@ - org.apache.maven.plugins @@ -402,7 +401,6 @@ true - org.codehaus.mojo buildnumber-maven-plugin @@ -420,7 +418,88 @@ false + + de.thetaphi + forbiddenapis + 1.6.1 + + + check-forbidden-apis + + 1.7 + + true + + false + + jsr166e/** + + org/elasticsearch/common/lucene/search/Queries$QueryWrapperFilterFactory.class + + + + org/elasticsearch/common/util/UnsafeUtils.class + + + org/elasticsearch/common/util/MathUtils.class + org/elasticsearch/common/math/UnboxedMathUtils.class + org/elasticsearch/cluster/routing/operation/plain/PlainOperationRouting.class + + + + org/elasticsearch/common/lucene/search/XFilteredQuery.class + + + org/elasticsearch/common/io/Channels.class + + + + + jdk-unsafe + jdk-deprecated + jdk-system-out + + + core-signatures.txt + all-signatures.txt + + + + compile + + check + + + + check-forbidden-test-apis + + 1.7 + + true + + false + + org/quartz/** + + + + jdk-unsafe + jdk-deprecated + + + test-signatures.txt + all-signatures.txt + + + + test-compile + + testCheck + + + + diff --git a/src/main/java/org/elasticsearch/alerts/actions/email/service/Email.java b/src/main/java/org/elasticsearch/alerts/actions/email/service/Email.java index e0cb41e1e24..bf450c507ed 100644 --- a/src/main/java/org/elasticsearch/alerts/actions/email/service/Email.java +++ b/src/main/java/org/elasticsearch/alerts/actions/email/service/Email.java @@ -337,7 +337,7 @@ public class Email implements ToXContent { if (name == null) { return defaultPriority; } - switch (name.toLowerCase()) { + switch (name.toLowerCase(Locale.ROOT)) { case "highest": return HIGHEST; case "high": return HIGH; case "normal": return NORMAL; diff --git a/src/main/java/org/elasticsearch/alerts/actions/email/service/Profile.java b/src/main/java/org/elasticsearch/alerts/actions/email/service/Profile.java index 1143ca77c9c..8fdf4ceb22e 100644 --- a/src/main/java/org/elasticsearch/alerts/actions/email/service/Profile.java +++ b/src/main/java/org/elasticsearch/alerts/actions/email/service/Profile.java @@ -111,7 +111,7 @@ public enum Profile implements ToXContent { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - return builder.value(name().toLowerCase()); + return builder.value(name().toLowerCase(Locale.ROOT)); } static MimeMessage createCommon(Email email, Session session) throws MessagingException { diff --git a/src/main/java/org/elasticsearch/alerts/history/FiredAlert.java b/src/main/java/org/elasticsearch/alerts/history/FiredAlert.java index 88ddb690f2e..a69dffe286f 100644 --- a/src/main/java/org/elasticsearch/alerts/history/FiredAlert.java +++ b/src/main/java/org/elasticsearch/alerts/history/FiredAlert.java @@ -10,6 +10,7 @@ import org.elasticsearch.ElasticsearchIllegalArgumentException; import org.elasticsearch.alerts.Alert; import org.elasticsearch.alerts.AlertExecution; import org.elasticsearch.alerts.AlertsException; +import org.elasticsearch.alerts.AlertsSettingsException; import org.elasticsearch.alerts.actions.ActionRegistry; import org.elasticsearch.alerts.condition.Condition; import org.elasticsearch.alerts.condition.ConditionRegistry; @@ -26,6 +27,7 @@ import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentParser; import java.io.IOException; +import java.util.Locale; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; @@ -127,7 +129,7 @@ public class FiredAlert implements ToXContent { historyEntry.field(Parser.FIRE_TIME_FIELD.getPreferredName(), fireTime.toDateTimeISO()); historyEntry.field(Parser.SCHEDULED_FIRE_TIME_FIELD.getPreferredName(), scheduledTime.toDateTimeISO()); historyEntry.startObject(Alert.Parser.CONDITION_FIELD.getPreferredName()).field(condition.type(), condition, params).endObject(); - historyEntry.field(Parser.STATE_FIELD.getPreferredName(), state.toString()); + historyEntry.field(Parser.STATE_FIELD.getPreferredName(), state.id()); if (message != null) { historyEntry.field(Parser.MESSAGE_FIELD.getPreferredName(), message); @@ -174,45 +176,22 @@ public class FiredAlert implements ToXContent { EXECUTED, FAILED; + public String id() { + return name().toLowerCase(Locale.ROOT); + } + + public static State resolve(String id) { + try { + return valueOf(id.toUpperCase(Locale.ROOT)); + } catch (IllegalArgumentException iae) { + throw new AlertsSettingsException("unknown fired alert state [" + id + "]"); + } + } + @Override public String toString() { - switch (this) { - case AWAITS_EXECUTION: - return "AWAITS_EXECUTION"; - case CHECKING: - return "CHECKING"; - case EXECUTION_NOT_NEEDED: - return "EXECUTION_NOT_NEEDED"; - case EXECUTED: - return "EXECUTED"; - case FAILED: - return "FAILED"; - case THROTTLED: - return "THROTTLED"; - default: - return "EXECUTION_NOT_NEEDED"; - } + return id(); } - - public static State fromString(String value) { - switch(value.toUpperCase()) { - case "AWAITS_EXECUTION": - return AWAITS_EXECUTION; - case "CHECKING": - return CHECKING; - case "EXECUTION_NOT_NEEDED": - return EXECUTION_NOT_NEEDED; - case "EXECUTED": - return EXECUTED; - case "FAILED": - return FAILED; - case "THROTTLED": - return THROTTLED; - default: - throw new ElasticsearchIllegalArgumentException("unknown fired alert state [" + value + "]"); - } - } - } public static class Parser extends AbstractComponent { @@ -274,7 +253,7 @@ public class FiredAlert implements ToXContent { } else if (MESSAGE_FIELD.match(currentFieldName)) { alert.message = parser.textOrNull(); } else if (STATE_FIELD.match(currentFieldName)) { - alert.state = State.fromString(parser.text()); + alert.state = State.resolve(parser.text()); } else { throw new AlertsException("unable to parse fired alert. unexpected field [" + currentFieldName + "]"); } diff --git a/src/main/java/org/elasticsearch/alerts/history/HistoryStore.java b/src/main/java/org/elasticsearch/alerts/history/HistoryStore.java index 1474bbb3b70..28dde1499cf 100644 --- a/src/main/java/org/elasticsearch/alerts/history/HistoryStore.java +++ b/src/main/java/org/elasticsearch/alerts/history/HistoryStore.java @@ -111,7 +111,7 @@ public class HistoryStore extends AbstractComponent { } SearchResponse response = client.prepareSearch(ALERT_HISTORY_INDEX_PREFIX + "*") - .setQuery(QueryBuilders.termQuery(FiredAlert.Parser.STATE_FIELD.getPreferredName(), firedAlertState.toString())) + .setQuery(QueryBuilders.termQuery(FiredAlert.Parser.STATE_FIELD.getPreferredName(), firedAlertState.id())) .setSearchType(SearchType.SCAN) .setScroll(scrollTimeout) .setSize(scrollSize) diff --git a/src/test/java/org/elasticsearch/alerts/AbstractAlertingTests.java b/src/test/java/org/elasticsearch/alerts/AbstractAlertingTests.java index 9433c4c174c..4d4c87eed96 100644 --- a/src/test/java/org/elasticsearch/alerts/AbstractAlertingTests.java +++ b/src/test/java/org/elasticsearch/alerts/AbstractAlertingTests.java @@ -270,7 +270,7 @@ public abstract class AbstractAlertingTests extends ElasticsearchIntegrationTest SearchResponse searchResponse = client().prepareSearch(HistoryStore.ALERT_HISTORY_INDEX_PREFIX + "*") .setIndicesOptions(IndicesOptions.lenientExpandOpen()) - .setQuery(boolQuery().must(matchQuery("alert_name", alertName)).must(matchQuery("state", FiredAlert.State.EXECUTED.toString()))) + .setQuery(boolQuery().must(matchQuery("alert_name", alertName)).must(matchQuery("state", FiredAlert.State.EXECUTED.id()))) .get(); assertThat(searchResponse.getHits().getTotalHits(), greaterThanOrEqualTo(minimumExpectedAlertActionsWithActionPerformed)); if (assertConditionMet) { @@ -283,7 +283,7 @@ public abstract class AbstractAlertingTests extends ElasticsearchIntegrationTest protected long findNumberOfPerformedActions(String alertName) { SearchResponse searchResponse = client().prepareSearch(HistoryStore.ALERT_HISTORY_INDEX_PREFIX + "*") .setIndicesOptions(IndicesOptions.lenientExpandOpen()) - .setQuery(boolQuery().must(matchQuery("alert_name", alertName)).must(matchQuery("state", FiredAlert.State.EXECUTED.toString()))) + .setQuery(boolQuery().must(matchQuery("alert_name", alertName)).must(matchQuery("state", FiredAlert.State.EXECUTED.id()))) .get(); return searchResponse.getHits().getTotalHits(); } @@ -304,7 +304,7 @@ public abstract class AbstractAlertingTests extends ElasticsearchIntegrationTest SearchResponse searchResponse = client().prepareSearch(HistoryStore.ALERT_HISTORY_INDEX_PREFIX + "*") .setIndicesOptions(IndicesOptions.lenientExpandOpen()) - .setQuery(boolQuery().must(matchQuery("alert_name", alertName)).must(matchQuery("state", FiredAlert.State.EXECUTION_NOT_NEEDED.toString()))) + .setQuery(boolQuery().must(matchQuery("alert_name", alertName)).must(matchQuery("state", FiredAlert.State.EXECUTION_NOT_NEEDED.id()))) .get(); assertThat(searchResponse.getHits().getTotalHits(), greaterThanOrEqualTo(expectedAlertActionsWithNoActionNeeded)); } diff --git a/src/test/java/org/elasticsearch/alerts/AlertThrottleTests.java b/src/test/java/org/elasticsearch/alerts/AlertThrottleTests.java index 44757bbc893..ebdaf715668 100644 --- a/src/test/java/org/elasticsearch/alerts/AlertThrottleTests.java +++ b/src/test/java/org/elasticsearch/alerts/AlertThrottleTests.java @@ -127,7 +127,7 @@ public class AlertThrottleTests extends AbstractAlertingTests { CountResponse countOfThrottledActions = client() .prepareCount(HistoryStore.ALERT_HISTORY_INDEX_PREFIX + "*") - .setQuery(QueryBuilders.matchQuery(FiredAlert.Parser.STATE_FIELD.getPreferredName(), FiredAlert.State.THROTTLED.toString())) + .setQuery(QueryBuilders.matchQuery(FiredAlert.Parser.STATE_FIELD.getPreferredName(), FiredAlert.State.THROTTLED.id())) .get(); assertThat(countOfThrottledActions.getCount(), greaterThan(0L)); } @@ -204,7 +204,7 @@ public class AlertThrottleTests extends AbstractAlertingTests { CountResponse countOfThrottledActions = client() .prepareCount(HistoryStore.ALERT_HISTORY_INDEX_PREFIX + "*") - .setQuery(QueryBuilders.matchQuery(FiredAlert.Parser.STATE_FIELD.getPreferredName(), FiredAlert.State.THROTTLED.toString())) + .setQuery(QueryBuilders.matchQuery(FiredAlert.Parser.STATE_FIELD.getPreferredName(), FiredAlert.State.THROTTLED.id())) .get(); assertThat(countOfThrottledActions.getCount(), greaterThan(0L)); } diff --git a/src/test/java/org/elasticsearch/alerts/BasicAlertingTest.java b/src/test/java/org/elasticsearch/alerts/BasicAlertingTest.java index fd80715310e..987a2998dfc 100644 --- a/src/test/java/org/elasticsearch/alerts/BasicAlertingTest.java +++ b/src/test/java/org/elasticsearch/alerts/BasicAlertingTest.java @@ -26,6 +26,8 @@ import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.junit.Test; +import java.util.Locale; + import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.index.query.FilterBuilders.rangeFilter; import static org.elasticsearch.index.query.QueryBuilders.*; @@ -257,7 +259,7 @@ public class BasicAlertingTest extends AbstractAlertingTests { alertClient().prepareDeleteAlert(alertName).get(); alertClient().preparePutAlert(alertName) - .setAlertSource(createAlertSource(String.format("0/%s * * * * ? *", (scheduleTimeInMs / 1000)), request, "return hits.total >= 3")) + .setAlertSource(createAlertSource(String.format(Locale.ROOT, "0/%s * * * * ? *", (scheduleTimeInMs / 1000)), request, "return hits.total >= 3")) .get(); long time1 = System.currentTimeMillis(); diff --git a/src/test/java/org/elasticsearch/alerts/BootStrapTest.java b/src/test/java/org/elasticsearch/alerts/BootStrapTest.java index fba932c61cc..da2dc5c802f 100644 --- a/src/test/java/org/elasticsearch/alerts/BootStrapTest.java +++ b/src/test/java/org/elasticsearch/alerts/BootStrapTest.java @@ -177,7 +177,7 @@ public class BootStrapTest extends AbstractAlertingTests { public void run() { CountResponse countResponse = client().prepareCount(HistoryStore.ALERT_HISTORY_INDEX_PREFIX + "*") .setTypes(HistoryStore.ALERT_HISTORY_TYPE) - .setQuery(QueryBuilders.termQuery(FiredAlert.Parser.STATE_FIELD.getPreferredName(), FiredAlert.State.EXECUTED.toString())).get(); + .setQuery(QueryBuilders.termQuery(FiredAlert.Parser.STATE_FIELD.getPreferredName(), FiredAlert.State.EXECUTED.id())).get(); assertEquals(totalHistoryEntries, countResponse.getCount()); } diff --git a/test-signatures.txt b/test-signatures.txt new file mode 100644 index 00000000000..e69de29bb2d