Skip to content

Commit

Permalink
Last batch of findbugs fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
laa committed Aug 11, 2015
1 parent 558a967 commit ddf047a
Show file tree
Hide file tree
Showing 28 changed files with 443 additions and 418 deletions.
12 changes: 12 additions & 0 deletions core/pom.xml
Expand Up @@ -128,6 +128,18 @@
<failOnError>false</failOnError>
<includeFilterFile>findbugs_filter.xml</includeFilterFile>
</configuration>
<executions>
<!--
Ensures that FindBugs inspects source code when project is compiled.
-->
<execution>
<id>analyze-compile</id>
<phase>compile</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
Expand Down
Expand Up @@ -23,6 +23,7 @@
import com.orientechnologies.common.util.OCallable;
import com.orientechnologies.common.util.OResettable;
import com.orientechnologies.common.util.OSizeable;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.lang.reflect.Array;
import java.util.*;
Expand All @@ -44,10 +45,9 @@ public class OMultiValue {
* @return true if it's an array, a collection or a map, otherwise false
*/
public static boolean isMultiValue(final Class<?> iType) {
return OCollection.class.isAssignableFrom(iType)
|| Collection.class.isAssignableFrom(iType)
|| (iType.isArray() || Map.class.isAssignableFrom(iType) || OMultiCollectionIterator.class.isAssignableFrom(iType) || OCollection.class
.isAssignableFrom(iType));
return OCollection.class.isAssignableFrom(iType) || Collection.class.isAssignableFrom(iType)
|| (iType.isArray() || Map.class.isAssignableFrom(iType) || OMultiCollectionIterator.class.isAssignableFrom(iType)
|| OCollection.class.isAssignableFrom(iType));
}

/**
Expand Down Expand Up @@ -114,7 +114,7 @@ else if (iObject instanceof Map<?, ?>)
return ((Map<?, Object>) iObject).values().iterator().next();
else if (iObject.getClass().isArray())
return Array.get(iObject, 0);
} catch (Exception e) {
} catch (RuntimeException e) {
// IGNORE IT
OLogManager.instance().debug(iObject, "Error on reading the first item of the Multi-value field '%s'", iObject);
}
Expand Down Expand Up @@ -151,7 +151,7 @@ else if (iObject instanceof Iterable<?>) {
return last;
} else if (iObject.getClass().isArray())
return Array.get(iObject, Array.getLength(iObject) - 1);
} catch (Exception e) {
} catch (RuntimeException e) {
// IGNORE IT
OLogManager.instance().debug(iObject, "Error on reading the last item of the Multi-value field '%s'", iObject);
}
Expand Down Expand Up @@ -214,7 +214,7 @@ else if (iObject instanceof Iterator<?> || iObject instanceof Iterable<?>) {
if (it instanceof OResettable)
((OResettable) it).reset();
}
} catch (Exception e) {
} catch (RuntimeException e) {
// IGNORE IT
OLogManager.instance().debug(iObject, "Error on reading the first item of the Multi-value field '%s'", iObject);
}
Expand Down Expand Up @@ -332,6 +332,7 @@ public static String toString(final Object iObject) {
* Single value, array of values or collections of values. Map are not supported.
* @return
*/
@SuppressFBWarnings("BC_UNCONFIRMED_CAST")
public static Object add(final Object iObject, final Object iToAdd) {
if (iObject != null) {
if (iObject instanceof Collection<?> || iObject instanceof OCollection<?>) {
Expand Down Expand Up @@ -628,6 +629,7 @@ public static <T> T[] array(final Object iValue, final Class<? extends T> iClass
return array(iValue, iClass, null);
}

@SuppressFBWarnings("PZLA_PREFER_ZERO_LENGTH_ARRAYS")
public static <T> T[] array(final Object iValue, final Class<? extends T> iClass, final OCallable<Object, Object> iCallback) {
if (iValue == null)
return null;
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/com/orientechnologies/orient/core/index/OCompositeCollate.java 100644 → 100755
Expand Up @@ -6,6 +6,7 @@
import com.orientechnologies.orient.core.collate.OCollate;

public class OCompositeCollate implements OCollate {
private static final long serialVersionUID = 8683726773893639905L;
/**
*
*/
Expand Down
Expand Up @@ -19,19 +19,23 @@
*/
package com.orientechnologies.orient.core.index;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.*;

import com.orientechnologies.common.comparator.ODefaultComparator;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.serialization.ODocumentSerializable;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* Container for the list of heterogeneous values that are going to be stored in in index as composite keys.
*
* @author Andrey lomakin, Artem Orobets
* @see com.orientechnologies.orient.core.index.mvrbtree.OMVRBTree.PartialSearchMode
*/
@SuppressFBWarnings(value = "SE_TRANSIENT_FIELD_NOT_RESTORED")
public class OCompositeKey implements Comparable<OCompositeKey>, Serializable, ODocumentSerializable {
private static final long serialVersionUID = 1L;
/**
Expand Down
Expand Up @@ -84,8 +84,8 @@ public static String extractFieldName(final String fieldDefinition) {
if (fieldNameParts.length == 3 && "by".equalsIgnoreCase(fieldNameParts[1]))
return fieldNameParts[0];

throw new IllegalArgumentException("Illegal field name format, should be '<property> [by key|value]' but was '"
+ fieldDefinition + '\'');
throw new IllegalArgumentException(
"Illegal field name format, should be '<property> [by key|value]' but was '" + fieldDefinition + '\'');
}

private static OIndexDefinition createMultipleFieldIndexDefinition(final OClass oClass, final List<String> fieldsToIndex,
Expand All @@ -99,8 +99,8 @@ private static OIndexDefinition createMultipleFieldIndexDefinition(final OClass
if (collates != null)
collate = collates.get(i);

compositeIndex.addIndex(createSingleFieldIndexDefinition(oClass, fieldsToIndex.get(i), types.get(i), collate, indexKind,
algorithm));
compositeIndex
.addIndex(createSingleFieldIndexDefinition(oClass, fieldsToIndex.get(i), types.get(i), collate, indexKind, algorithm));
}

return compositeIndex;
Expand Down Expand Up @@ -177,27 +177,32 @@ else if (type.equals(OType.LINKLIST)) {
}

private static OPropertyMapIndexDefinition.INDEX_BY extractMapIndexSpecifier(final String fieldName) {

String[] fieldNameParts = FILED_NAME_PATTERN.split(fieldName);
if (fieldNameParts.length == 1)
return OPropertyMapIndexDefinition.INDEX_BY.KEY;

if (fieldNameParts.length == 3) {
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.get();
OStorage storage = db.getStorage();
OStorageConfiguration configuration = storage.getConfiguration();
Locale locale = configuration.getLocaleInstance();
Locale locale = getServerLocale();

if ("by".equals(fieldNameParts[1].toLowerCase(locale)))
try {
return OPropertyMapIndexDefinition.INDEX_BY.valueOf(fieldNameParts[2].toUpperCase());
return OPropertyMapIndexDefinition.INDEX_BY.valueOf(fieldNameParts[2].toUpperCase(locale));
} catch (IllegalArgumentException iae) {
throw new IllegalArgumentException("Illegal field name format, should be '<property> [by key|value]' but was '"
+ fieldName + '\'', iae);
throw new IllegalArgumentException(
"Illegal field name format, should be '<property> [by key|value]' but was '" + fieldName + '\'', iae);
}
}

throw new IllegalArgumentException("Illegal field name format, should be '<property> [by key|value]' but was '" + fieldName
+ '\'');
throw new IllegalArgumentException(
"Illegal field name format, should be '<property> [by key|value]' but was '" + fieldName + '\'');
}

private static Locale getServerLocale() {
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.get();
OStorage storage = db.getStorage();
OStorageConfiguration configuration = storage.getConfiguration();
return configuration.getLocaleInstance();
}

private static String adjustFieldName(final OClass clazz, final String fieldName) {
Expand Down
Expand Up @@ -51,14 +51,14 @@ public class OIndexFullText extends OIndexMultiValues {
private static final String DEF_SEPARATOR_CHARS = " \r\n\t:;,.|+*/\\=!?[]()";
private static final String DEF_IGNORE_CHARS = "'\"";
private static final String DEF_STOP_WORDS = "the in a at as and or for his her " + "him this that what which while "
+ "up with be was were is";
+ "up with be was were is";
private static int DEF_MIN_WORD_LENGTH = 3;
private boolean indexRadix;
private String separatorChars;
private String ignoreChars;
private int minWordLength;

private Set<String> stopWords;
private Set<String> stopWords;

public OIndexFullText(String name, String typeId, String algorithm, OIndexEngine<Set<OIdentifiable>> indexEngine,
String valueContainerAlgorithm, ODocument metadata) {
Expand Down Expand Up @@ -277,7 +277,8 @@ protected void config() {
private Set<String> splitIntoWords(final String iKey) {
final Set<String> result = new HashSet<String>();

final List<String> words = (List<String>) OStringSerializerHelper.split(new ArrayList<String>(), iKey, 0, -1, separatorChars);
final List<String> words = new ArrayList<String>();
OStringSerializerHelper.split(words, iKey, 0, -1, separatorChars);

final StringBuilder buffer = new StringBuilder(64);
// FOREACH WORD CREATE THE LINK TO THE CURRENT DOCUMENT
Expand Down
Expand Up @@ -361,7 +361,7 @@ public OIndex<?> getClassIndex(String className, String indexName) {

final OIndex<?> index = indexes.get(indexName);
if (index != null && index.getDefinition() != null && index.getDefinition().getClassName() != null
&& className.equals(index.getDefinition().getClassName().toLowerCase()))
&& className.equals(index.getDefinition().getClassName().toLowerCase(locale)))
return preProcessBeforeReturn(index);
return null;
}
Expand Down Expand Up @@ -425,7 +425,7 @@ protected void addIndexInternal(final OIndex<?> index) {
if (indexDefinition == null || indexDefinition.getClassName() == null)
return;

Map<OMultiKey, Set<OIndex<?>>> propertyIndex = classPropertyIndex.get(indexDefinition.getClassName().toLowerCase());
Map<OMultiKey, Set<OIndex<?>>> propertyIndex = classPropertyIndex.get(indexDefinition.getClassName().toLowerCase(locale));

if (propertyIndex == null) {
propertyIndex = new HashMap<OMultiKey, Set<OIndex<?>>>();
Expand All @@ -449,7 +449,7 @@ protected void addIndexInternal(final OIndex<?> index) {
propertyIndex.put(multiKey, indexSet);
}

classPropertyIndex.put(indexDefinition.getClassName().toLowerCase(), copyPropertyMap(propertyIndex));
classPropertyIndex.put(indexDefinition.getClassName().toLowerCase(locale), copyPropertyMap(propertyIndex));
} finally {
releaseExclusiveLock();
}
Expand Down
Expand Up @@ -40,6 +40,7 @@
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.storage.OStorage;
import com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.util.*;

Expand All @@ -49,7 +50,8 @@
* @author Luca Garulli (l.garulli--at--orientechnologies.com)
* @author Artem Orobets added composite index managemement
*/
public class OIndexManagerShared extends OIndexManagerAbstract implements OIndexManager {
@SuppressFBWarnings("EQ_DOESNT_OVERRIDE_EQUALS")
public class OIndexManagerShared extends OIndexManagerAbstract {
private static final long serialVersionUID = 1L;

protected volatile transient Thread recreateIndexesThread = null;
Expand Down Expand Up @@ -379,7 +381,7 @@ protected void fromStream() {
configUpdated = true;
}
}
} catch (Exception e) {
} catch (RuntimeException e) {
indexConfigurationIterator.remove();
configUpdated = true;
OLogManager.instance().error(this, "Error on loading index by configuration: %s", e, d);
Expand Down Expand Up @@ -413,7 +415,8 @@ public void removeClassPropertyIndex(final OIndex<?> idx) {
if (indexDefinition == null || indexDefinition.getClassName() == null)
return;

Map<OMultiKey, Set<OIndex<?>>> map = classPropertyIndex.get(indexDefinition.getClassName().toLowerCase());
final Locale locale = getServerLocale();
Map<OMultiKey, Set<OIndex<?>>> map = classPropertyIndex.get(indexDefinition.getClassName().toLowerCase(locale));

if (map == null) {
return;
Expand Down Expand Up @@ -441,7 +444,7 @@ public void removeClassPropertyIndex(final OIndex<?> idx) {
}
}

final Locale locale = getServerLocale();

if (map.isEmpty())
classPropertyIndex.remove(indexDefinition.getClassName().toLowerCase(locale));
else
Expand Down
Expand Up @@ -149,7 +149,7 @@ public OIndexMultiValues put(Object key, final OIdentifiable iSingleValue) {
}

if (!iSingleValue.getIdentity().isValid())
((ORecord) iSingleValue).save();
(iSingleValue.getRecord()).save();

values.add(iSingleValue.getIdentity());
indexEngine.put(key, values);
Expand Down Expand Up @@ -238,8 +238,8 @@ public OIndexMultiValues create(final String name, final OIndexDefinition indexD

protected OStreamSerializer determineValueSerializer() {
if (ODefaultIndexFactory.SBTREEBONSAI_VALUE_CONTAINER.equals(valueContainerAlgorithm))
return (OStreamSerializer) getDatabase().getSerializerFactory().getObjectSerializer(
OStreamSerializerSBTreeIndexRIDContainer.ID);
return (OStreamSerializer) getDatabase().getSerializerFactory()
.getObjectSerializer(OStreamSerializerSBTreeIndexRIDContainer.ID);
else
return OStreamSerializerListRID.INSTANCE;
}
Expand Down Expand Up @@ -304,10 +304,10 @@ public OIndexCursor iterateEntries(Collection<?> keys, boolean ascSortOrder) {
Collections.sort(sortedKeys, comparator);

return new OIndexAbstractCursor() {
private Iterator<?> keysIterator = sortedKeys.iterator();
private Iterator<?> keysIterator = sortedKeys.iterator();

private Iterator<OIdentifiable> currentIterator = OEmptyIterator.IDENTIFIABLE_INSTANCE;
private Object currentKey;
private Object currentKey;

@Override
public Map.Entry<Object, OIdentifiable> nextEntry() {
Expand Down
Expand Up @@ -56,29 +56,29 @@ public abstract class OIndexRemote<T> implements OIndex<T> {
protected final static String QUERY_ENTRIES = "select key, rid from index:%s";
protected final static String QUERY_ENTRIES_DESC = "select key, rid from index:%s order by key desc";

private final static String QUERY_GET_ENTRIES = "select from index:%s where key in [%s]";

private final static String QUERY_PUT = "insert into index:%s (key,rid) values (?,?)";
private final static String QUERY_REMOVE = "delete from index:%s where key = ?";
private final static String QUERY_REMOVE2 = "delete from index:%s where key = ? and rid = ?";
private final static String QUERY_REMOVE3 = "delete from index:%s where rid = ?";
private final static String QUERY_CONTAINS = "select count(*) as size from index:%s where key = ?";
private final static String QUERY_COUNT = "select count(*) as size from index:%s where key = ?";
private final static String QUERY_COUNT_RANGE = "select count(*) as size from index:%s where ";
private final static String QUERY_SIZE = "select count(*) as size from index:%s";
private final static String QUERY_KEY_SIZE = "select count(distinct( key )) as size from index:%s";
private final static String QUERY_KEYS = "select key from index:%s";
private final static String QUERY_REBUILD = "rebuild index %s";
private final static String QUERY_CLEAR = "delete from index:%s";
private final static String QUERY_DROP = "drop index %s";
protected final String databaseName;
private final String wrappedType;
private final String algorithm;
private final ORID rid;
protected OIndexDefinition indexDefinition;
protected String name;
protected ODocument configuration;
protected Set<String> clustersToIndex;
private final static String QUERY_GET_ENTRIES = "select from index:%s where key in [%s]";

private final static String QUERY_PUT = "insert into index:%s (key,rid) values (?,?)";
private final static String QUERY_REMOVE = "delete from index:%s where key = ?";
private final static String QUERY_REMOVE2 = "delete from index:%s where key = ? and rid = ?";
private final static String QUERY_REMOVE3 = "delete from index:%s where rid = ?";
private final static String QUERY_CONTAINS = "select count(*) as size from index:%s where key = ?";
private final static String QUERY_COUNT = "select count(*) as size from index:%s where key = ?";
private final static String QUERY_COUNT_RANGE = "select count(*) as size from index:%s where ";
private final static String QUERY_SIZE = "select count(*) as size from index:%s";
private final static String QUERY_KEY_SIZE = "select count(distinct( key )) as size from index:%s";
private final static String QUERY_KEYS = "select key from index:%s";
private final static String QUERY_REBUILD = "rebuild index %s";
private final static String QUERY_CLEAR = "delete from index:%s";
private final static String QUERY_DROP = "drop index %s";
protected final String databaseName;
private final String wrappedType;
private final String algorithm;
private final ORID rid;
protected OIndexDefinition indexDefinition;
protected String name;
protected ODocument configuration;
protected Set<String> clustersToIndex;

public OIndexRemote(final String iName, final String iWrappedType, final String algorithm, final ORID iRid,
final OIndexDefinition iIndexDefinition, final ODocument iConfiguration, final Set<String> clustersToIndex) {
Expand Down Expand Up @@ -263,7 +263,7 @@ public long rebuild(final OProgressListener iProgressListener) {
public OType[] getKeyTypes() {
if (indexDefinition != null)
return indexDefinition.getTypes();
return null;
return new OType[0];
}

public Collection<ODocument> getEntries(final Collection<?> iKeys) {
Expand Down
Expand Up @@ -35,7 +35,7 @@
* {@link com.orientechnologies.orient.core.metadata.schema.OType#LINKSET} or
* {@link com.orientechnologies.orient.core.metadata.schema.OType#EMBEDDEDSET} properties.
*/
public class OPropertyListIndexDefinition extends OAbstractIndexDefinitionMultiValue implements OIndexDefinitionMultiValue {
public class OPropertyListIndexDefinition extends OAbstractIndexDefinitionMultiValue {

private static final long serialVersionUID = -6499782365051906190L;

Expand Down

0 comments on commit ddf047a

Please sign in to comment.