[OLINGO-750] Fixes for critical issues from static code check

This commit is contained in:
Michael Bolz 2015-08-10 10:24:14 +02:00
parent 6d64cbd556
commit 1d88d9c986
21 changed files with 102 additions and 83 deletions

View File

@ -21,31 +21,30 @@ package org.apache.olingo.client.api;
/**
* Constant values related to the OData protocol.
*/
public class ODataBatchConstants {
public interface ODataBatchConstants {
/**
* Batch item content type.
*/
public static final String ITEM_CONTENT_TYPE = "application/http";
String ITEM_CONTENT_TYPE = "application/http";
/**
* Boundary key.
*/
public static final String BOUNDARY = "boundary";
String BOUNDARY = "boundary";
/**
* Item content type.
*/
public static String ITEM_CONTENT_TYPE_LINE = "Content-Type: application/http";
String ITEM_CONTENT_TYPE_LINE = "Content-Type: application/http";
/**
* Item transfer encoding.
*/
public static String ITEM_TRANSFER_ENCODING_LINE = "Content-Transfer-Encoding: binary";
String ITEM_TRANSFER_ENCODING_LINE = "Content-Transfer-Encoding: binary";
/**
* Content id header name.
*/
public static String CHANGESET_CONTENT_ID_NAME = "Content-ID";
String CHANGESET_CONTENT_ID_NAME = "Content-ID";
}

View File

@ -21,6 +21,7 @@ package org.apache.olingo.client.api;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import org.apache.olingo.commons.api.ODataRuntimeException;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.format.ContentType;
@ -99,6 +100,9 @@ public final class ODataClientBuilder {
}
}
/** Empty private constructor for static helper class */
private ODataClientBuilder() {}
/**
* Create an new ODataClient based on via system property ODATA_CLIENT_IMPL_SYS_PROPERTY
* class name or if not net the default ODATA_CLIENT_IMPL_CLASS set class.
@ -161,15 +165,19 @@ public final class ODataClientBuilder {
Constructor<?> ctor = clazz.getConstructor(ctorParameterClasses);
return typeOfClass.cast(ctor.newInstance(ctorParameters));
} catch (ClassNotFoundException e) {
throw new RuntimeException("Requested class '" + className + "' could not be loaded.", e);
throw wrapException(className, e);
} catch (InstantiationException e) {
throw new RuntimeException("Requested class '" + className + "' could not be loaded.", e);
throw wrapException(className, e);
} catch (IllegalAccessException e) {
throw new RuntimeException("Requested class '" + className + "' could not be loaded.", e);
throw wrapException(className, e);
} catch (NoSuchMethodException e) {
throw new RuntimeException("Requested class '" + className + "' could not be loaded.", e);
throw wrapException(className, e);
} catch (InvocationTargetException e) {
throw new RuntimeException("Requested class '" + className + "' could not be loaded.", e);
throw wrapException(className, e);
}
}
private static ODataRuntimeException wrapException(String className, Exception e) {
return new ODataRuntimeException("Requested class '" + className + "' could not be loaded.", e);
}
}

View File

@ -30,63 +30,63 @@ public interface EdmEnabledInvokeRequestFactory extends InvokeRequestFactory {
/**
* Gets an invoke request instance for the function import with the given name and no parameters.
*
* @param <RES> OData domain object result, derived from return type defined in the function import
* @param <T> OData domain object result, derived from return type defined in the function import
* @param functionImportName operation to be invoked
* @return new {@link ODataInvokeRequest} instance.
*/
<RES extends ClientInvokeResult> ODataInvokeRequest<RES> getFunctionImportInvokeRequest(
<T extends ClientInvokeResult> ODataInvokeRequest<T> getFunctionImportInvokeRequest(
String functionImportName);
/**
* Gets an invoke request instance for the function import with the given name and matching parameter names.
*
* @param <RES> OData domain object result, derived from return type defined in the function import
* @param <T> OData domain object result, derived from return type defined in the function import
* @param functionImportName operation to be invoked
* @param parameters parameters to pass to operation import invocation
* @return new {@link ODataInvokeRequest} instance.
*/
<RES extends ClientInvokeResult> ODataInvokeRequest<RES> getFunctionImportInvokeRequest(
<T extends ClientInvokeResult> ODataInvokeRequest<T> getFunctionImportInvokeRequest(
String functionImportName, Map<String, ClientValue> parameters);
/**
* Gets an invoke request instance for the action import with the given name.
*
* @param <RES> OData domain object result, derived from return type defined in the action import
* @param <T> OData domain object result, derived from return type defined in the action import
* @param actionImportName operation to be invoked
* @return new {@link ODataInvokeRequest} instance.
*/
<RES extends ClientInvokeResult> ODataInvokeRequest<RES> getActionImportInvokeRequest(
<T extends ClientInvokeResult> ODataInvokeRequest<T> getActionImportInvokeRequest(
String actionImportName);
/**
* Gets an invoke request instance for the action import with the given name.
*
* @param <RES> OData domain object result, derived from return type defined in the action import
* @param <T> OData domain object result, derived from return type defined in the action import
* @param actionImportName operation to be invoked
* @param parameters parameters to pass to operation import invocation
* @return new {@link ODataInvokeRequest} instance.
*/
<RES extends ClientInvokeResult> ODataInvokeRequest<RES> getActionImportInvokeRequest(
<T extends ClientInvokeResult> ODataInvokeRequest<T> getActionImportInvokeRequest(
String actionImportName, Map<String, ClientValue> parameters);
/**
* Gets an invoke request instance for the function bound to given URI (no parameters).
*
* @param <RES> OData domain object result
* @param <T> OData domain object result
* @param bindingParameterURI binding parameter URI
* @param functionName operation to be invoked
* @param bindingParameterTypeName binding parameter type full qualified name
* @param isBindingParameterCollection whether binding parameter is collection
* @return new {@link ODataInvokeRequest} instance.
*/
<RES extends ClientInvokeResult> ODataInvokeRequest<RES> getBoundFunctionInvokeRequest(
<T extends ClientInvokeResult> ODataInvokeRequest<T> getBoundFunctionInvokeRequest(
URI bindingParameterURI, FullQualifiedName functionName, FullQualifiedName bindingParameterTypeName,
Boolean isBindingParameterCollection);
/**
* Gets an invoke request instance for the function bound to given URI (with parameters).
*
* @param <RES> OData domain object result
* @param <T> OData domain object result
* @param bindingParameterURI binding parameter URI
* @param functionName operation to be invoked
* @param bindingParameterTypeName binding parameter type full qualified name
@ -94,28 +94,28 @@ public interface EdmEnabledInvokeRequestFactory extends InvokeRequestFactory {
* @param parameters parameters to pass to function invocation
* @return new {@link ODataInvokeRequest} instance.
*/
<RES extends ClientInvokeResult> ODataInvokeRequest<RES> getBoundFunctionInvokeRequest(
<T extends ClientInvokeResult> ODataInvokeRequest<T> getBoundFunctionInvokeRequest(
URI bindingParameterURI, FullQualifiedName functionName, FullQualifiedName bindingParameterTypeName,
Boolean isBindingParameterCollection, Map<String, ClientValue> parameters);
/**
* Gets an invoke request instance for the action bound to given URI (no parameters).
*
* @param <RES> OData domain object result
* @param <T> OData domain object result
* @param bindingParameterURI binding parameter URI
* @param actionName operation to be invoked
* @param bindingParameterTypeName binding parameter type full qualified name
* @param isBindingParameterCollection whether binding parameter is collection
* @return new {@link ODataInvokeRequest} instance.
*/
<RES extends ClientInvokeResult> ODataInvokeRequest<RES> getBoundActionInvokeRequest(
<T extends ClientInvokeResult> ODataInvokeRequest<T> getBoundActionInvokeRequest(
URI bindingParameterURI, FullQualifiedName actionName, FullQualifiedName bindingParameterTypeName,
Boolean isBindingParameterCollection);
/**
* Gets an invoke request instance for the action bound to given URI (with parameters).
*
* @param <RES> OData domain object result
* @param <T> OData domain object result
* @param bindingParameterURI binding parameter URI
* @param actionName operation to be invoked
* @param bindingParameterTypeName binding parameter type full qualified name
@ -123,7 +123,7 @@ public interface EdmEnabledInvokeRequestFactory extends InvokeRequestFactory {
* @param parameters parameters to pass to function invocation
* @return new {@link ODataInvokeRequest} instance.
*/
<RES extends ClientInvokeResult> ODataInvokeRequest<RES> getBoundActionInvokeRequest(
<T extends ClientInvokeResult> ODataInvokeRequest<T> getBoundActionInvokeRequest(
URI bindingParameterURI, FullQualifiedName actionName, FullQualifiedName bindingParameterTypeName,
Boolean isBindingParameterCollection, Map<String, ClientValue> parameters);

View File

@ -36,57 +36,57 @@ public interface InvokeRequestFactory {
* This method is mainly meant for internal usage, but defined for generic calls from proxy; normally, one of other
* methods should be used instead.
*
* @param <RES> OData domain object result
* @param <T> OData domain object result
* @param method HTTP invocation method
* @param uri invocation URI
* @param resultRef reference Class for result
* @param parameters parameters to pass to function invocation
* @return new {@link ODataInvokeRequest} instance.
*/
<RES extends ClientInvokeResult> ODataInvokeRequest<RES> getInvokeRequest(
HttpMethod method, URI uri, Class<RES> resultRef, Map<String, ClientValue> parameters);
<T extends ClientInvokeResult> ODataInvokeRequest<T> getInvokeRequest(
HttpMethod method, URI uri, Class<T> resultRef, Map<String, ClientValue> parameters);
/**
* Gets an invoke request instance for the function bound to given URI (no parameters).
*
* @param <RES> OData domain object result
* @param <T> OData domain object result
* @param uri invocation URI
* @param resultRef reference Class for result
* @return new {@link ODataInvokeRequest} instance.
*/
<RES extends ClientInvokeResult> ODataInvokeRequest<RES> getFunctionInvokeRequest(URI uri, Class<RES> resultRef);
<T extends ClientInvokeResult> ODataInvokeRequest<T> getFunctionInvokeRequest(URI uri, Class<T> resultRef);
/**
* Gets an invoke request instance for the function bound to given URI (with parameters).
*
* @param <RES> OData domain object result
* @param <T> OData domain object result
* @param uri invocation URI
* @param resultRef reference Class for result
* @param parameters parameters to pass to function invocation
* @return new {@link ODataInvokeRequest} instance.
*/
<RES extends ClientInvokeResult> ODataInvokeRequest<RES> getFunctionInvokeRequest(
URI uri, Class<RES> resultRef, Map<String, ClientValue> parameters);
<T extends ClientInvokeResult> ODataInvokeRequest<T> getFunctionInvokeRequest(
URI uri, Class<T> resultRef, Map<String, ClientValue> parameters);
/**
* Gets an invoke request instance for the action bound to given URI (no parameters).
*
* @param <RES> OData domain object result
* @param <T> OData domain object result
* @param uri invocation URI
* @param resultRef reference Class for result
* @return new {@link ODataInvokeRequest} instance.
*/
<RES extends ClientInvokeResult> ODataInvokeRequest<RES> getActionInvokeRequest(URI uri, Class<RES> resultRef);
<T extends ClientInvokeResult> ODataInvokeRequest<T> getActionInvokeRequest(URI uri, Class<T> resultRef);
/**
* Gets an invoke request instance for the action bound to given URI (with parameters).
*
* @param <RES> OData domain object result
* @param <T> OData domain object result
* @param uri invocation URI
* @param resultRef reference Class for result
* @param parameters parameters to pass to action invocation
* @return new {@link ODataInvokeRequest} instance.
*/
<RES extends ClientInvokeResult> ODataInvokeRequest<RES> getActionInvokeRequest(
URI uri, Class<RES> resultRef, Map<String, ClientValue> parameters);
<T extends ClientInvokeResult> ODataInvokeRequest<T> getActionInvokeRequest(
URI uri, Class<T> resultRef, Map<String, ClientValue> parameters);
}

View File

@ -23,16 +23,16 @@ import java.util.Collection;
/**
* OData collection property value.
*
* @param <OV> The actual ODataValue interface.
* @param <T> The actual ODataValue interface.
*/
public interface ClientCollectionValue<OV extends ClientValue> extends ClientValue, Iterable<OV> {
public interface ClientCollectionValue<T extends ClientValue> extends ClientValue, Iterable<T> {
/**
* Adds a value to the collection.
*
* @param value value to be added.
*/
ClientCollectionValue<OV> add(ClientValue value);
ClientCollectionValue<T> add(ClientValue value);
/**
* Checks if collection is empty.

View File

@ -44,9 +44,9 @@ import org.slf4j.LoggerFactory;
* <b>Please don't forget to call the <tt>close()>/</tt> method when not needed any more.</b>
*
* @param <E> concrete ODataEntity implementation
* @param <ES> concrete ODataEntitySet implementation
* @param <T> concrete ODataEntitySet implementation
*/
public class ClientEntitySetIterator<ES extends ClientEntitySet, E extends ClientEntity>
public class ClientEntitySetIterator<T extends ClientEntitySet, E extends ClientEntity>
implements Iterator<E> {
/**
@ -62,7 +62,7 @@ public class ClientEntitySetIterator<ES extends ClientEntitySet, E extends Clien
private final ContentType contentType;
private ES entitySet;
private T entitySet;
private final ByteArrayOutputStream osEntitySet;
@ -118,7 +118,7 @@ public class ClientEntitySetIterator<ES extends ClientEntitySet, E extends Clien
if (cached == null) {
available = false;
try {
entitySet = (ES) odataClient.getReader().
entitySet = (T) odataClient.getReader().
readEntitySet(new ByteArrayInputStream(osEntitySet.toByteArray()), contentType);
} catch (final ODataDeserializerException e) {
available = false;

View File

@ -45,7 +45,7 @@ public abstract class ClientItem {
/**
* OData item self link.
*/
protected URI link;
private URI link;
/**
* Constructor.

View File

@ -31,11 +31,11 @@ public class ClientLink extends ClientItem implements ClientAnnotatable {
public static class Builder {
protected URI uri;
private URI uri;
protected ClientLinkType type;
private ClientLinkType type;
protected String title;
private String title;
public Builder setURI(final URI uri) {
this.uri = uri;
@ -88,17 +88,17 @@ public class ClientLink extends ClientItem implements ClientAnnotatable {
/**
* Link type.
*/
protected final ClientLinkType type;
private final ClientLinkType type;
/**
* Link rel.
*/
protected final String rel;
private final String rel;
/**
* ETag for media edit links.
*/
protected String mediaETag;
private String mediaETag;
private final List<ClientAnnotation> annotations = new ArrayList<ClientAnnotation>();
@ -112,8 +112,8 @@ public class ClientLink extends ClientItem implements ClientAnnotatable {
public ClientLink(final URI uri, final ClientLinkType type, final String title) {
super(title);
link = uri;
this.type = type;
setLink(uri);
switch (this.type) {
case ASSOCIATION:

View File

@ -55,10 +55,10 @@ public interface ClientValue {
/**
* Casts to collection value.
*
* @param <OV> The actual ODataValue interface.
* @param <T> The actual ODataValue interface.
* @return collection value.
*/
<OV extends ClientValue> ClientCollectionValue<OV> asCollection();
<T extends ClientValue> ClientCollectionValue<T> asCollection();
/**
* Casts to complex value.

View File

@ -21,7 +21,7 @@ package org.apache.olingo.client.api.uri;
public interface FilterArgFactory {
FilterArg _null();
FilterArg nullValue();
FilterArg add(FilterArg first, FilterArg second);

View File

@ -25,7 +25,7 @@ import org.apache.olingo.client.api.uri.URIFilter;
public class FilterArgFactoryImpl implements FilterArgFactory {
@Override
public FilterArg _null() {
public FilterArg nullValue() {
return new FilterConst("null");
}

View File

@ -35,7 +35,7 @@ public enum ODataPreferenceNames {
private final String preferenceName;
private ODataPreferenceNames(final String preferenceName) {
ODataPreferenceNames(final String preferenceName) {
this.preferenceName = preferenceName;
}

View File

@ -41,9 +41,9 @@ public abstract class ODataLibraryException extends ODataException {
protected static final String DEFAULT_SERVER_BUNDLE_NAME = "server-core-exceptions-i18n";
/** Key for the exception text in the resource bundle. */
public static interface MessageKey {
public interface MessageKey {
/** Gets this key. */
public String getKey();
String getKey();
}
private MessageKey messageKey;
@ -137,9 +137,9 @@ public abstract class ODataLibraryException extends ODataException {
}
/** Error message text and {@link Locale} used for it. */
public class ODataErrorMessage {
String message;
Locale locale;
public static class ODataErrorMessage {
private String message;
private Locale locale;
public ODataErrorMessage(final String message, final Locale usedLocale) {
this.message = message;

View File

@ -24,7 +24,7 @@ package org.apache.olingo.server.api.deserializer.batch;
* {@link org.apache.olingo.server.api.deserializer.FixedFormatDeserializer
* #parseBatchRequest(java.io.InputStream, String, BatchOptions)}
*/
public class BatchOptions {
public final class BatchOptions {
private boolean isStrict = true;
private String rawBaseUri = "";
private String rawServiceResolutionUri = "";

View File

@ -19,9 +19,11 @@
package org.apache.olingo.server.api.prefer;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import org.apache.olingo.commons.api.ODataPreferenceNames;
import org.apache.olingo.server.api.prefer.Preferences.Return;
@ -31,8 +33,9 @@ import org.apache.olingo.server.api.prefer.Preferences.Return;
* as described in <a href="https://www.ietf.org/rfc/rfc7240.txt">RFC 7240</a>.
* There are named methods for preferences defined in the OData standard.
*/
public class PreferencesApplied {
public final class PreferencesApplied {
private static final Set<String> SAFE_PREFERENCE_NAMES = new HashSet<String>();
private Map<String, String> applied;
private PreferencesApplied() {
@ -57,14 +60,7 @@ public class PreferencesApplied {
final String key = entry.getKey();
result.append(key);
if (entry.getValue() != null) {
final boolean safe = ODataPreferenceNames.ALLOW_ENTITY_REFERENCES.toString().equals(key)
|| ODataPreferenceNames.CALLBACK.toString().equals(key)
|| ODataPreferenceNames.CONTINUE_ON_ERROR.toString().equals(key)
|| ODataPreferenceNames.MAX_PAGE_SIZE.toString().equals(key)
|| ODataPreferenceNames.TRACK_CHANGES.toString().equals(key)
|| ODataPreferenceNames.RETURN.toString().equals(key)
|| ODataPreferenceNames.RESPOND_ASYNC.toString().equals(key)
|| ODataPreferenceNames.WAIT.toString().equals(key);
final boolean safe = isSafe(key);
result.append('=')
.append(safe ? "" : '"')
.append(entry.getValue().replaceAll("\\\\|\"", "\\\\$0"))
@ -74,6 +70,20 @@ public class PreferencesApplied {
return result.toString();
}
private boolean isSafe(String key) {
if(SAFE_PREFERENCE_NAMES.isEmpty()) {
SAFE_PREFERENCE_NAMES.add(ODataPreferenceNames.ALLOW_ENTITY_REFERENCES.toString());
SAFE_PREFERENCE_NAMES.add(ODataPreferenceNames.CALLBACK.toString());
SAFE_PREFERENCE_NAMES.add(ODataPreferenceNames.CONTINUE_ON_ERROR.toString());
SAFE_PREFERENCE_NAMES.add(ODataPreferenceNames.MAX_PAGE_SIZE.toString());
SAFE_PREFERENCE_NAMES.add(ODataPreferenceNames.TRACK_CHANGES.toString());
SAFE_PREFERENCE_NAMES.add(ODataPreferenceNames.RETURN.toString());
SAFE_PREFERENCE_NAMES.add(ODataPreferenceNames.RESPOND_ASYNC.toString());
SAFE_PREFERENCE_NAMES.add(ODataPreferenceNames.WAIT.toString());
}
return SAFE_PREFERENCE_NAMES.contains(key);
}
@Override
public String toString() {
return toValueString();

View File

@ -19,6 +19,8 @@
package org.apache.olingo.server.api.processor;
import java.io.ByteArrayInputStream;
import java.nio.charset.Charset;
import java.util.Locale;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.api.http.HttpHeader;
@ -116,7 +118,7 @@ public class DefaultProcessor implements MetadataProcessor, ServiceDocumentProce
// This should never happen but to be sure we have this catch here to prevent sending a stacktrace to a client.
String responseContent =
"{\"error\":{\"code\":null,\"message\":\"An unexpected exception occurred during error processing\"}}";
response.setContent(new ByteArrayInputStream(responseContent.getBytes()));
response.setContent(new ByteArrayInputStream(responseContent.getBytes(Charset.forName("utf-8"))));
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, ContentType.APPLICATION_JSON.toContentTypeString());
}

View File

@ -36,6 +36,6 @@ public interface ErrorProcessor extends Processor {
* @param serverError the server error
* @param responseFormat requested content type after content negotiation
*/
public void processError(ODataRequest request, ODataResponse response, ODataServerError serverError,
void processError(ODataRequest request, ODataResponse response, ODataServerError serverError,
ContentType responseFormat);
}

View File

@ -22,7 +22,7 @@ import org.apache.olingo.commons.api.data.ContextURL;
import org.apache.olingo.commons.api.edm.EdmProperty;
/** Options for the OData serializer. */
public class PrimitiveSerializerOptions {
public final class PrimitiveSerializerOptions {
private ContextURL contextURL;
private Boolean isNullable;

View File

@ -22,7 +22,7 @@ import org.apache.olingo.commons.api.data.ContextURL;
import org.apache.olingo.server.api.uri.queryoption.CountOption;
/** Options for the OData serializer. */
public class ReferenceCollectionSerializerOptions {
public final class ReferenceCollectionSerializerOptions {
private ContextURL contextURL;
private CountOption count;

View File

@ -20,7 +20,7 @@ package org.apache.olingo.server.api.serializer;
import org.apache.olingo.commons.api.data.ContextURL;
public class ReferenceSerializerOptions {
public final class ReferenceSerializerOptions {
private ContextURL contextURL;
/** Gets the {@link ContextURL}. */

View File

@ -84,9 +84,9 @@ public enum SystemQueryOptionKind {
*/
LEVELS("$level");
String syntax;
private String syntax;
private SystemQueryOptionKind(final String syntax) {
SystemQueryOptionKind(final String syntax) {
this.syntax = syntax;
}