You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2021/12/02 08:42:47 UTC

[sling-org-apache-sling-models-impl] branch master updated: cosmetic: cleanup code, apply null annotations, eliminate code warnings, remove unused imports

This is an automated email from the ASF dual-hosted git repository.

sseifert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-models-impl.git


The following commit(s) were added to refs/heads/master by this push:
     new 1e160bb  cosmetic: cleanup code, apply null annotations, eliminate code warnings, remove unused imports
1e160bb is described below

commit 1e160bbf04face58ab88e0654dcc32221efe1d42
Author: Stefan Seifert <st...@users.noreply.github.com>
AuthorDate: Thu Dec 2 09:42:31 2021 +0100

    cosmetic: cleanup code, apply null annotations, eliminate code warnings, remove unused imports
---
 pom.xml                                            |  1 -
 .../apache/sling/models/impl/ExportServlet.java    |  1 -
 .../models/impl/FirstImplementationPicker.java     |  3 +-
 .../sling/models/impl/ModelAdapterFactory.java     | 41 +++++++++--------
 .../models/impl/ModelPackageBundleListener.java    |  4 +-
 .../apache/sling/models/impl/ReflectionUtil.java   |  2 +
 .../impl/ResourceTypeBasedResourcePicker.java      |  2 +-
 .../java/org/apache/sling/models/impl/Result.java  | 12 ++---
 .../models/impl/injectors/BindingsInjector.java    |  3 +-
 .../impl/injectors/ChildResourceInjector.java      |  1 +
 .../models/impl/injectors/OSGiServiceInjector.java |  2 +
 .../impl/injectors/RequestAttributeInjector.java   |  5 ++-
 .../impl/injectors/ResourcePathInjector.java       |  2 +
 .../sling/models/impl/injectors/SelfInjector.java  |  3 +-
 .../models/impl/injectors/SlingObjectInjector.java |  3 +-
 .../models/impl/injectors/ValueMapInjector.java    |  4 +-
 .../impl/model/AbstractInjectableElement.java      |  3 ++
 .../models/impl/model/ConstructorParameter.java    | 14 +++---
 .../sling/models/impl/AdapterFactoryTest.java      |  4 +-
 .../models/impl/AdapterImplementationsTest.java    | 51 +++++++++++-----------
 .../org/apache/sling/models/impl/CachingTest.java  | 12 +++--
 .../apache/sling/models/impl/ConstructorTest.java  | 13 ++++--
 .../impl/InjectorSpecificAnnotationTest.java       |  3 ++
 .../sling/models/impl/OSGiInjectionTest.java       |  9 ++++
 .../sling/models/impl/RequestDisposalTest.java     | 34 ++++++++-------
 .../models/impl/ResourceModelClassesTest.java      |  2 +
 .../models/impl/ResourceModelInterfacesTest.java   |  1 +
 .../models/testutil/ModelAdapterFactoryUtil.java   | 20 ++++-----
 28 files changed, 146 insertions(+), 109 deletions(-)

diff --git a/pom.xml b/pom.xml
index b8bbe9a..6aba679 100644
--- a/pom.xml
+++ b/pom.xml
@@ -146,7 +146,6 @@
         <dependency>
             <groupId>javax.inject</groupId>
             <artifactId>javax.inject</artifactId>
-            <version>1</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
diff --git a/src/main/java/org/apache/sling/models/impl/ExportServlet.java b/src/main/java/org/apache/sling/models/impl/ExportServlet.java
index f557713..29c980e 100644
--- a/src/main/java/org/apache/sling/models/impl/ExportServlet.java
+++ b/src/main/java/org/apache/sling/models/impl/ExportServlet.java
@@ -148,7 +148,6 @@ class ExportServlet extends SlingSafeMethodsServlet {
 
     }
 
-    @SuppressWarnings("unchecked")
     private Map<String, String> createOptionMap(SlingHttpServletRequest request) {
         Map<String, String[]> parameterMap = request.getParameterMap();
         String[] selectors = request.getRequestPathInfo().getSelectors();
diff --git a/src/main/java/org/apache/sling/models/impl/FirstImplementationPicker.java b/src/main/java/org/apache/sling/models/impl/FirstImplementationPicker.java
index 2963739..89b6c96 100644
--- a/src/main/java/org/apache/sling/models/impl/FirstImplementationPicker.java
+++ b/src/main/java/org/apache/sling/models/impl/FirstImplementationPicker.java
@@ -19,6 +19,7 @@
 package org.apache.sling.models.impl;
 
 import org.apache.sling.models.spi.ImplementationPicker;
+import org.jetbrains.annotations.NotNull;
 import org.osgi.framework.Constants;
 import org.osgi.service.component.annotations.Component;
 
@@ -33,7 +34,7 @@ import org.osgi.service.component.annotations.Component;
 public class FirstImplementationPicker implements ImplementationPicker {
 
     @Override
-    public Class<?> pick(Class<?> adapterType, Class<?>[] implementationsTypes, Object adaptable) {
+    public Class<?> pick(@NotNull Class<?> adapterType, Class<?> @NotNull [] implementationsTypes, @NotNull Object adaptable) {
         // implementations is never null or empty
         return implementationsTypes[0];
     }
diff --git a/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java b/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
index d216586..4cfb367 100644
--- a/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
+++ b/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
@@ -107,8 +107,8 @@ import org.osgi.service.metatype.annotations.Designate;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-@Component(immediate = true, service={ ModelFactory.class, ServletRequestListener.class }, 
-    property= { HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER+"=true", 
+@Component(immediate = true, service={ ModelFactory.class, ServletRequestListener.class },
+    property= { HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER+"=true",
                 HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT+"=(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=*)" })
 @Designate(ocd=ModelAdapterFactoryConfiguration.class)
 @SuppressWarnings("deprecation")
@@ -218,31 +218,31 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
 
     private static final Logger log = LoggerFactory.getLogger(ModelAdapterFactory.class);
 
-    private final @NotNull ConcurrentMap<String, RankedServices<Injector>> injectors = new ConcurrentHashMap<>();
-    private final @NotNull RankedServices<Injector> sortedInjectors = new RankedServices<>();
-    private final @NotNull ConcurrentMap<Class<? extends ViaProviderType>, ViaProvider> viaProviders = new ConcurrentHashMap<>();
+    private final ConcurrentMap<String, RankedServices<Injector>> injectors = new ConcurrentHashMap<>();
+    private final RankedServices<Injector> sortedInjectors = new RankedServices<>();
+    private final ConcurrentMap<Class<? extends ViaProviderType>, ViaProvider> viaProviders = new ConcurrentHashMap<>();
 
     @Reference(name="injectAnnotationProcessorFactory", cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
-    volatile @NotNull Collection<InjectAnnotationProcessorFactory> injectAnnotationProcessorFactories; // this must be non-final for fieldOption=replace!
+    volatile Collection<InjectAnnotationProcessorFactory> injectAnnotationProcessorFactories; // this must be non-final for fieldOption=replace!
 
     @Reference(name="injectAnnotationProcessorFactory2", cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
-    volatile @NotNull Collection<InjectAnnotationProcessorFactory2> injectAnnotationProcessorFactories2; // this must be non-final for fieldOption=replace!
+    volatile Collection<InjectAnnotationProcessorFactory2> injectAnnotationProcessorFactories2; // this must be non-final for fieldOption=replace!
 
-    private final @NotNull RankedServices<StaticInjectAnnotationProcessorFactory> staticInjectAnnotationProcessorFactories = new RankedServices<>();
+    private final RankedServices<StaticInjectAnnotationProcessorFactory> staticInjectAnnotationProcessorFactories = new RankedServices<>();
 
-    private final @NotNull RankedServices<ImplementationPicker> implementationPickers = new RankedServices<>();
+    private final RankedServices<ImplementationPicker> implementationPickers = new RankedServices<>();
 
     // bind the service with the highest priority (if a new one comes in this service gets restarted)
     @Reference(cardinality=ReferenceCardinality.OPTIONAL, policyOption=ReferencePolicyOption.GREEDY)
     private ModelValidation modelValidation = null;
 
     @Reference(name = "modelExporter", cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
-    volatile @NotNull Collection<ModelExporter> modelExporters; // this must be non-final for fieldOption=replace!
+    volatile Collection<ModelExporter> modelExporters; // this must be non-final for fieldOption=replace!
 
     @Reference
     BindingsValuesProvidersByContext bindingsValuesProvidersByContext;
 
-    @Reference 
+    @Reference
     AdapterManager adapterManager;
 
     ModelPackageBundleListener listener;
@@ -260,12 +260,8 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
 
     private SlingModelsScriptEngineFactory scriptEngineFactory;
 
-    // use a smaller initial capacity than the default as we expect a relatively small number of
-    // adapters per adaptable
-    private final int INNER_CACHE_INITIAL_CAPACITY = 4;
-
-
     @Override
+    @SuppressWarnings("null")
     public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
         Result<AdapterType> result = internalCreateModel(adaptable, type);
         if (!result.wasSuccessful()) {
@@ -345,7 +341,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
         // throw exception here
         throw new ModelClassException("Could not yet find an adapter factory for the model " + requestedType + " from adaptable " + adaptable.getClass());
     }
-    
+
     @SuppressWarnings("unchecked")
     private Map<Class<?>, SoftReference<Object>> getOrCreateCache(final Object adaptable) {
         Map<Class<?>, SoftReference<Object>> adaptableCache;
@@ -361,7 +357,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
         }
         return adaptableCache;
     }
-    
+
     @SuppressWarnings("unchecked")
     private <ModelType> Result<ModelType> internalCreateModel(final Object adaptable, final Class<ModelType> requestedType) {
         Result<ModelType> result;
@@ -620,7 +616,6 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
     }
 
     private BundleContext getModelBundleContext(final ModelClass<?> modelClass) {
-        BundleContext modelContext = null;
         Bundle modelBundle = FrameworkUtil.getBundle(modelClass.getType());
         if (modelBundle != null) {
             return modelBundle.getBundleContext();
@@ -940,6 +935,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
         return true;
     }
 
+    @SuppressWarnings("null")
     private <ModelType> ModelType invokePostConstruct(ModelType object) throws InvocationTargetException, IllegalAccessException {
         Class<?> clazz = object.getClass();
         List<Method> postConstructMethods = new ArrayList<>();
@@ -1007,6 +1003,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
         }
     }
 
+    @SuppressWarnings("null")
     private Result<Object> adaptIfNecessary(final Object value, final Class<?> type, final Type genericType) {
         final Object adaptedValue;
         if (!isAcceptableType(type, genericType, value)) {
@@ -1072,6 +1069,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
         }
     }
 
+    @SuppressWarnings("null")
     private static boolean isAcceptableType(Class<?> type, Type genericType, Object value) {
         if (type.isInstance(value)) {
             if ((type == Collection.class || type == List.class) && genericType instanceof ParameterizedType &&
@@ -1280,7 +1278,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
     }
 
     @Override
-    public Object getModelFromResource(Resource resource) {
+    public Object getModelFromResource(@NotNull Resource resource) {
         Class<?> clazz = this.adapterImplementations.getModelClassForResource(resource);
         if (clazz == null) {
             throw new ModelClassException("Could find model registered for resource type: " + resource.getResourceType());
@@ -1289,7 +1287,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
     }
 
     @Override
-    public Object getModelFromRequest(SlingHttpServletRequest request) {
+    public Object getModelFromRequest(@NotNull SlingHttpServletRequest request) {
         Class<?> clazz = this.adapterImplementations.getModelClassForRequest(request);
         if (clazz == null) {
             throw new ModelClassException("Could find model registered for request path: " + request.getServletPath());
@@ -1306,6 +1304,7 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
     }
 
     @Override
+    @SuppressWarnings("null")
     public <T> T exportModel(Object model, String name, Class<T> targetClass, Map<String, String> options)
             throws ExportException, MissingExporterException {
         for (ModelExporter exporter : modelExporters) {
diff --git a/src/main/java/org/apache/sling/models/impl/ModelPackageBundleListener.java b/src/main/java/org/apache/sling/models/impl/ModelPackageBundleListener.java
index 8928d46..b80377a 100644
--- a/src/main/java/org/apache/sling/models/impl/ModelPackageBundleListener.java
+++ b/src/main/java/org/apache/sling/models/impl/ModelPackageBundleListener.java
@@ -111,9 +111,7 @@ public class ModelPackageBundleListener implements BundleTrackerCustomizer<Servi
             packageList = StringUtils.deleteWhitespace(packageList);
             String[] packages = packageList.split(",");
             for (String singlePackage : packages) {
-                @SuppressWarnings("unchecked")
-                Enumeration<URL> classUrls = bundle.findEntries("/" + singlePackage.replace('.', '/'), "*.class",
-                        true);
+                Enumeration<URL> classUrls = bundle.findEntries("/" + singlePackage.replace('.', '/'), "*.class", true);
 
                 if (classUrls == null) {
                     log.warn("No adaptable classes found in package {}, ignoring", singlePackage);
diff --git a/src/main/java/org/apache/sling/models/impl/ReflectionUtil.java b/src/main/java/org/apache/sling/models/impl/ReflectionUtil.java
index da985a4..456b1c7 100644
--- a/src/main/java/org/apache/sling/models/impl/ReflectionUtil.java
+++ b/src/main/java/org/apache/sling/models/impl/ReflectionUtil.java
@@ -70,6 +70,7 @@ public final class ReflectionUtil {
         }
     }
 
+    @SuppressWarnings("unused")
     public static <T extends AnnotatedElement> void addAnnotated(T[] elements, List<T> set) {
         for (T element : elements) {
             Inject injection = getAnnotation(element, Inject.class);
@@ -92,6 +93,7 @@ public final class ReflectionUtil {
      * @param annotationClass the annotation class
      * @return the found annotation or null
      */
+    @SuppressWarnings("null")
     public static <T extends Annotation> T getAnnotation(AnnotatedElement element, Class<T> annotationClass) {
         T annotation = element.getAnnotation(annotationClass);
         if (annotation != null) {
diff --git a/src/main/java/org/apache/sling/models/impl/ResourceTypeBasedResourcePicker.java b/src/main/java/org/apache/sling/models/impl/ResourceTypeBasedResourcePicker.java
index 7bf313a..00df685 100644
--- a/src/main/java/org/apache/sling/models/impl/ResourceTypeBasedResourcePicker.java
+++ b/src/main/java/org/apache/sling/models/impl/ResourceTypeBasedResourcePicker.java
@@ -31,7 +31,7 @@ import org.osgi.service.component.annotations.Component;
 public class ResourceTypeBasedResourcePicker implements ImplementationPicker {
 
     @Override
-    public Class<?> pick(@NotNull Class<?> adapterType, @NotNull Class<?>[] implementationsTypes, @NotNull Object adaptable) {
+    public Class<?> pick(@NotNull Class<?> adapterType, Class<?> @NotNull [] implementationsTypes, @NotNull Object adaptable) {
         final Resource resource = findResource(adaptable);
         if (resource == null) {
             return null;
diff --git a/src/main/java/org/apache/sling/models/impl/Result.java b/src/main/java/org/apache/sling/models/impl/Result.java
index 26f3c7c..d056c92 100644
--- a/src/main/java/org/apache/sling/models/impl/Result.java
+++ b/src/main/java/org/apache/sling/models/impl/Result.java
@@ -32,9 +32,10 @@ public class Result<SuccessObjectType> {
     private final SuccessObjectType object;
     /**
      * instantiate with one throwable (i.e. failure)
-     * 
+     *
      * @param throwable
      */
+    @SuppressWarnings("null")
     public Result(RuntimeException throwable) {
         this.t = throwable;
         this.object = null;
@@ -42,7 +43,7 @@ public class Result<SuccessObjectType> {
 
     /**
      * instantate with a model (i.e. success)
-     * 
+     *
      * @param object
      */
     public Result(SuccessObjectType object) {
@@ -51,7 +52,7 @@ public class Result<SuccessObjectType> {
     }
 
     /**
-     * 
+     *
      * @return the encapsulated exception
      * @throws IllegalStateException
      *             in case this object does not represent a failure
@@ -64,11 +65,12 @@ public class Result<SuccessObjectType> {
     }
 
     /**
-     * 
+     *
      * @return the encapsulated success value
      * @throws IllegalStateException
      *             in case this object does not represent a success
      */
+    @SuppressWarnings("null")
     public @NotNull SuccessObjectType getValue() {
         if (object == null) {
             throw new IllegalStateException(
@@ -78,7 +80,7 @@ public class Result<SuccessObjectType> {
     }
 
     /**
-     * 
+     *
      * @return {@code true} in case this object represents a success, otherwise
      *         {@code false}
      */
diff --git a/src/main/java/org/apache/sling/models/impl/injectors/BindingsInjector.java b/src/main/java/org/apache/sling/models/impl/injectors/BindingsInjector.java
index 4562217..1fd5495 100644
--- a/src/main/java/org/apache/sling/models/impl/injectors/BindingsInjector.java
+++ b/src/main/java/org/apache/sling/models/impl/injectors/BindingsInjector.java
@@ -68,6 +68,7 @@ public class BindingsInjector implements Injector, StaticInjectAnnotationProcess
     }
 
     @Override
+    @SuppressWarnings("unused")
     public InjectAnnotationProcessor2 createAnnotationProcessor(AnnotatedElement element) {
         // check if the element has the expected annotation
         ScriptVariable annotation = element.getAnnotation(ScriptVariable.class);
@@ -78,7 +79,7 @@ public class BindingsInjector implements Injector, StaticInjectAnnotationProcess
     }
 
     @Override
-    public Object prepareValue(Object adaptable) {
+    public @NotNull Object prepareValue(@NotNull Object adaptable) {
         Object prepared = getBindings(adaptable);
         return prepared != null ? prepared : ObjectUtils.NULL;
     }
diff --git a/src/main/java/org/apache/sling/models/impl/injectors/ChildResourceInjector.java b/src/main/java/org/apache/sling/models/impl/injectors/ChildResourceInjector.java
index 967a531..b32cf7e 100644
--- a/src/main/java/org/apache/sling/models/impl/injectors/ChildResourceInjector.java
+++ b/src/main/java/org/apache/sling/models/impl/injectors/ChildResourceInjector.java
@@ -89,6 +89,7 @@ public class ChildResourceInjector extends AbstractInjector implements Injector,
 
 
     @Override
+    @SuppressWarnings("unused")
     public InjectAnnotationProcessor2 createAnnotationProcessor(Object adaptable, AnnotatedElement element) {
         // check if the element has the expected annotation
         ChildResource annotation = element.getAnnotation(ChildResource.class);
diff --git a/src/main/java/org/apache/sling/models/impl/injectors/OSGiServiceInjector.java b/src/main/java/org/apache/sling/models/impl/injectors/OSGiServiceInjector.java
index 5c02f73..88e6362 100644
--- a/src/main/java/org/apache/sling/models/impl/injectors/OSGiServiceInjector.java
+++ b/src/main/java/org/apache/sling/models/impl/injectors/OSGiServiceInjector.java
@@ -81,6 +81,7 @@ public class OSGiServiceInjector implements Injector, StaticInjectAnnotationProc
      * @param modelContext
      * @return
      */
+    @SuppressWarnings({ "null", "unused" })
     public Object getValue(@NotNull Object adaptable, String name, @NotNull Type type, @NotNull AnnotatedElement element,
                            @NotNull DisposalCallbackRegistry callbackRegistry, @Nullable BundleContext modelContext) {
         OSGiService annotation = element.getAnnotation(OSGiService.class);
@@ -207,6 +208,7 @@ public class OSGiServiceInjector implements Injector, StaticInjectAnnotationProc
     }
 
     @Override
+    @SuppressWarnings({ "unused", "null" })
     public InjectAnnotationProcessor2 createAnnotationProcessor(AnnotatedElement element) {
         // check if the element has the expected annotation
         OSGiService annotation = element.getAnnotation(OSGiService.class);
diff --git a/src/main/java/org/apache/sling/models/impl/injectors/RequestAttributeInjector.java b/src/main/java/org/apache/sling/models/impl/injectors/RequestAttributeInjector.java
index 93109dc..9df6b37 100644
--- a/src/main/java/org/apache/sling/models/impl/injectors/RequestAttributeInjector.java
+++ b/src/main/java/org/apache/sling/models/impl/injectors/RequestAttributeInjector.java
@@ -51,6 +51,7 @@ public class RequestAttributeInjector implements Injector, StaticInjectAnnotatio
     }
 
     @Override
+    @SuppressWarnings({ "unused", "null" })
     public InjectAnnotationProcessor2 createAnnotationProcessor(AnnotatedElement element) {
         // check if the element has the expected annotation
         RequestAttribute annotation = element.getAnnotation(RequestAttribute.class);
@@ -72,7 +73,7 @@ public class RequestAttributeInjector implements Injector, StaticInjectAnnotatio
         public InjectionStrategy getInjectionStrategy() {
             return annotation.injectionStrategy();
         }
-        
+
         @Override
         @SuppressWarnings("deprecation")
         public Boolean isOptional() {
@@ -90,5 +91,5 @@ public class RequestAttributeInjector implements Injector, StaticInjectAnnotatio
         }
     }
 
-    
+
 }
diff --git a/src/main/java/org/apache/sling/models/impl/injectors/ResourcePathInjector.java b/src/main/java/org/apache/sling/models/impl/injectors/ResourcePathInjector.java
index 2b3ff71..9bfe445 100644
--- a/src/main/java/org/apache/sling/models/impl/injectors/ResourcePathInjector.java
+++ b/src/main/java/org/apache/sling/models/impl/injectors/ResourcePathInjector.java
@@ -55,6 +55,7 @@ public class ResourcePathInjector extends AbstractInjector implements Injector,
     }
 
     @Override
+    @SuppressWarnings({ "unused", "null" })
     public Object getValue(@NotNull Object adaptable, String name, @NotNull Type declaredType, @NotNull AnnotatedElement element,
             @NotNull DisposalCallbackRegistry callbackRegistry) {
         String[] resourcePaths = null;
@@ -149,6 +150,7 @@ public class ResourcePathInjector extends AbstractInjector implements Injector,
     }
 
     @Override
+    @SuppressWarnings({ "unused", "null" })
     public InjectAnnotationProcessor2 createAnnotationProcessor(AnnotatedElement element) {
         // check if the element has the expected annotation
         ResourcePath annotation = element.getAnnotation(ResourcePath.class);
diff --git a/src/main/java/org/apache/sling/models/impl/injectors/SelfInjector.java b/src/main/java/org/apache/sling/models/impl/injectors/SelfInjector.java
index 9439d6d..d59192f 100644
--- a/src/main/java/org/apache/sling/models/impl/injectors/SelfInjector.java
+++ b/src/main/java/org/apache/sling/models/impl/injectors/SelfInjector.java
@@ -62,6 +62,7 @@ public class SelfInjector implements Injector, StaticInjectAnnotationProcessorFa
     }
 
     @Override
+    @SuppressWarnings({ "unused", "null" })
     public InjectAnnotationProcessor2 createAnnotationProcessor(AnnotatedElement element) {
         // check if the element has the expected annotation
         Self annotation = element.getAnnotation(Self.class);
@@ -83,7 +84,7 @@ public class SelfInjector implements Injector, StaticInjectAnnotationProcessorFa
         public InjectionStrategy getInjectionStrategy() {
             return annotation.injectionStrategy();
         }
-        
+
         @Override
         @SuppressWarnings("deprecation")
         public Boolean isOptional() {
diff --git a/src/main/java/org/apache/sling/models/impl/injectors/SlingObjectInjector.java b/src/main/java/org/apache/sling/models/impl/injectors/SlingObjectInjector.java
index 0f9124d..f582ad8 100644
--- a/src/main/java/org/apache/sling/models/impl/injectors/SlingObjectInjector.java
+++ b/src/main/java/org/apache/sling/models/impl/injectors/SlingObjectInjector.java
@@ -122,6 +122,7 @@ public final class SlingObjectInjector implements Injector, StaticInjectAnnotati
     }
 
     @Override
+    @SuppressWarnings({ "unused", "null" })
     public InjectAnnotationProcessor2 createAnnotationProcessor(final AnnotatedElement element) {
         // check if the element has the expected annotation
         SlingObject annotation = element.getAnnotation(SlingObject.class);
@@ -143,7 +144,7 @@ public final class SlingObjectInjector implements Injector, StaticInjectAnnotati
         public InjectionStrategy getInjectionStrategy() {
             return annotation.injectionStrategy();
         }
-        
+
         @Override
         @SuppressWarnings("deprecation")
         public Boolean isOptional() {
diff --git a/src/main/java/org/apache/sling/models/impl/injectors/ValueMapInjector.java b/src/main/java/org/apache/sling/models/impl/injectors/ValueMapInjector.java
index f24b367..06e91b1 100644
--- a/src/main/java/org/apache/sling/models/impl/injectors/ValueMapInjector.java
+++ b/src/main/java/org/apache/sling/models/impl/injectors/ValueMapInjector.java
@@ -55,6 +55,7 @@ public class ValueMapInjector extends AbstractInjector implements Injector, Inje
     }
 
     @Override
+    @SuppressWarnings({ "unused", "null" })
     public Object getValue(@NotNull Object adaptable, String name, @NotNull Type type, @NotNull AnnotatedElement element,
             @NotNull DisposalCallbackRegistry callbackRegistry) {
         if (adaptable == ObjectUtils.NULL) {
@@ -135,12 +136,13 @@ public class ValueMapInjector extends AbstractInjector implements Injector, Inje
     }
 
     @Override
-    public Object prepareValue(final Object adaptable) {
+    public @NotNull Object prepareValue(final @NotNull Object adaptable) {
         Object prepared = getValueMap(adaptable);
         return prepared != null ? prepared : ObjectUtils.NULL;
     }
 
     @Override
+    @SuppressWarnings({ "unused", "null" })
     public InjectAnnotationProcessor createAnnotationProcessor(Object adaptable, AnnotatedElement element) {
         // check if the element has the expected annotation
         ValueMapValue annotation = element.getAnnotation(ValueMapValue.class);
diff --git a/src/main/java/org/apache/sling/models/impl/model/AbstractInjectableElement.java b/src/main/java/org/apache/sling/models/impl/model/AbstractInjectableElement.java
index ebc0189..72ccb18 100644
--- a/src/main/java/org/apache/sling/models/impl/model/AbstractInjectableElement.java
+++ b/src/main/java/org/apache/sling/models/impl/model/AbstractInjectableElement.java
@@ -83,6 +83,7 @@ abstract class AbstractInjectableElement implements InjectableElement {
         return null;
     }
 
+    @SuppressWarnings("unused")
     private static String getName(AnnotatedElement element, String defaultName, InjectAnnotationProcessor2 annotationProcessor) {
         String name = null;
         if (annotationProcessor != null) {
@@ -100,6 +101,7 @@ abstract class AbstractInjectableElement implements InjectableElement {
         return name;
     }
 
+    @SuppressWarnings("unused")
     private static String getSource(AnnotatedElement element) {
         Source source = ReflectionUtil.getAnnotation(element, Source.class);
         if (source != null) {
@@ -133,6 +135,7 @@ abstract class AbstractInjectableElement implements InjectableElement {
         return element.isAnnotationPresent(Default.class);
     }
 
+    @SuppressWarnings("unused")
     private static Object getDefaultValue(AnnotatedElement element, Type type, InjectAnnotationProcessor2 annotationProcessor) {
         if (annotationProcessor != null && annotationProcessor.hasDefault()) {
             return annotationProcessor.getDefault();
diff --git a/src/main/java/org/apache/sling/models/impl/model/ConstructorParameter.java b/src/main/java/org/apache/sling/models/impl/model/ConstructorParameter.java
index 72baeff..2eb525c 100644
--- a/src/main/java/org/apache/sling/models/impl/model/ConstructorParameter.java
+++ b/src/main/java/org/apache/sling/models/impl/model/ConstructorParameter.java
@@ -58,21 +58,21 @@ public class ConstructorParameter extends AbstractInjectableElement {
     public boolean isPrimitive() {
         return isPrimitive;
     }
-    
+
     public int getParameterIndex() {
         return this.parameterIndex;
     }
-    
+
     @Override
     public String toString() {
         return "Parameter" + this.parameterIndex + "[" + this.genericType.toString() + "]";
     }
 
     public static class FakeAnnotatedElement implements AnnotatedElement {
-        
+
         private final Annotation[] annotations;
         private final int parameterIndex;
-        
+
         public FakeAnnotatedElement(Annotation[] annotations, int parameterIndex) {
             this.annotations = annotations;
             this.parameterIndex = parameterIndex;
@@ -83,7 +83,7 @@ public class ConstructorParameter extends AbstractInjectableElement {
             return getAnnotation(paramClass) != null;
         }
 
-        @SuppressWarnings("unchecked")
+        @SuppressWarnings({ "unchecked", "null" })
         @Override
         public <T extends Annotation> T getAnnotation(Class<T> paramClass) {
             for (Annotation annotation : this.annotations) {
@@ -103,7 +103,7 @@ public class ConstructorParameter extends AbstractInjectableElement {
         public Annotation[] getDeclaredAnnotations() {
             return annotations;
         }
-        
+
         public int getParameterIndex() {
             return this.parameterIndex;
         }
@@ -115,5 +115,5 @@ public class ConstructorParameter extends AbstractInjectableElement {
         }
 
     }
-   
+
 }
diff --git a/src/test/java/org/apache/sling/models/impl/AdapterFactoryTest.java b/src/test/java/org/apache/sling/models/impl/AdapterFactoryTest.java
index af7bad7..e6a71e4 100644
--- a/src/test/java/org/apache/sling/models/impl/AdapterFactoryTest.java
+++ b/src/test/java/org/apache/sling/models/impl/AdapterFactoryTest.java
@@ -19,8 +19,6 @@ package org.apache.sling.models.impl;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
@@ -74,7 +72,7 @@ public class AdapterFactoryTest {
         BundleContext bundleContext = Mockito.mock(BundleContext.class);
         return createModelAdapterFactory(bundleContext);
     }
-    
+
     public static ModelAdapterFactory createModelAdapterFactory(BundleContext bundleContext) {
         ComponentContext componentCtx = Mockito.mock(ComponentContext.class);
         when(componentCtx.getBundleContext()).thenReturn(bundleContext);
diff --git a/src/test/java/org/apache/sling/models/impl/AdapterImplementationsTest.java b/src/test/java/org/apache/sling/models/impl/AdapterImplementationsTest.java
index 10c761c..1cfc541 100644
--- a/src/test/java/org/apache/sling/models/impl/AdapterImplementationsTest.java
+++ b/src/test/java/org/apache/sling/models/impl/AdapterImplementationsTest.java
@@ -29,6 +29,7 @@ import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.models.spi.ImplementationPicker;
 import org.apache.sling.testing.mock.osgi.MockOsgi;
+import org.jetbrains.annotations.NotNull;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -40,7 +41,7 @@ import org.osgi.framework.BundleContext;
 public class AdapterImplementationsTest {
 
     private static final Class<?> SAMPLE_ADAPTER = Comparable.class;
-    private static final Object SAMPLE_ADAPTABLE = new Object();    
+    private static final Object SAMPLE_ADAPTABLE = new Object();
 
     private AdapterImplementations underTest;
 
@@ -55,7 +56,7 @@ public class AdapterImplementationsTest {
 
     @Mock
     private ResourceResolver resourceResolver;
-    
+
     @Before
     public void setUp() {
         underTest = new AdapterImplementations();
@@ -63,21 +64,21 @@ public class AdapterImplementationsTest {
             new FirstImplementationPicker()
         }));
     }
-    
+
     @Test
     public void testNoMapping() {
         assertNull(underTest.lookup(SAMPLE_ADAPTER, SAMPLE_ADAPTABLE));
-        
+
         // make sure this raises no exception
         underTest.remove(SAMPLE_ADAPTER.getName(), String.class.getName());
     }
-    
+
     @Test
     public void testSingleMapping() {
         underTest.addAll(String.class, SAMPLE_ADAPTER);
-        
+
         assertEquals(String.class, underTest.lookup(SAMPLE_ADAPTER, SAMPLE_ADAPTABLE).getType());
-        
+
         underTest.remove(SAMPLE_ADAPTER.getName(), String.class.getName());
 
         assertNull(underTest.lookup(SAMPLE_ADAPTER, SAMPLE_ADAPTABLE));
@@ -88,30 +89,30 @@ public class AdapterImplementationsTest {
         underTest.addAll(String.class, SAMPLE_ADAPTER);
         underTest.addAll(Integer.class, SAMPLE_ADAPTER);
         underTest.addAll(Long.class, SAMPLE_ADAPTER);
-        
+
         assertEquals(Integer.class, underTest.lookup(SAMPLE_ADAPTER, SAMPLE_ADAPTABLE).getType());
-        
+
         underTest.remove(SAMPLE_ADAPTER.getName(), Integer.class.getName());
 
         assertEquals(Long.class, underTest.lookup(SAMPLE_ADAPTER, SAMPLE_ADAPTABLE).getType());
 
         underTest.remove(SAMPLE_ADAPTER.getName(), Long.class.getName());
         underTest.remove(SAMPLE_ADAPTER.getName(), String.class.getName());
-        
+
         assertNull(underTest.lookup(SAMPLE_ADAPTER, SAMPLE_ADAPTABLE));
     }
-    
+
     @Test
     public void testRemoveAll() {
         underTest.addAll(String.class, SAMPLE_ADAPTER);
         underTest.addAll(Integer.class, SAMPLE_ADAPTER);
         underTest.addAll(Long.class, SAMPLE_ADAPTER);
-        
+
         underTest.removeAll();
-        
+
         assertNull(underTest.lookup(SAMPLE_ADAPTER, SAMPLE_ADAPTABLE));
     }
-    
+
     @Test
     public void testMultipleImplementationPickers() {
         underTest.setImplementationPickers(Arrays.asList(
@@ -123,14 +124,14 @@ public class AdapterImplementationsTest {
         underTest.addAll(String.class, SAMPLE_ADAPTER);
         underTest.addAll(Integer.class, SAMPLE_ADAPTER);
         underTest.addAll(Long.class, SAMPLE_ADAPTER);
-        
+
         assertEquals(String.class, underTest.lookup(SAMPLE_ADAPTER, SAMPLE_ADAPTABLE).getType());
     }
-    
+
     @Test
     public void testSimpleModel() {
         underTest.addAll(SAMPLE_ADAPTER, SAMPLE_ADAPTER);
-        
+
         assertEquals(SAMPLE_ADAPTER, underTest.lookup(SAMPLE_ADAPTER, SAMPLE_ADAPTABLE).getType());
     }
 
@@ -243,7 +244,7 @@ public class AdapterImplementationsTest {
         assertNull(underTest.getModelClassForRequest(request));
         assertNull(underTest.getModelClassForResource(resource));
     }
-    
+
     @Test
     public void testResourceTypeRegistrationForResourceWithoutResourceType() {
         when(resource.getResourceType()).thenReturn(null);
@@ -253,19 +254,19 @@ public class AdapterImplementationsTest {
         // ensure we don't have any registrations and no exception is thrown
         assertNull(underTest.getModelClassForResource(resource));
     }
-    
+
     static final class NoneImplementationPicker implements ImplementationPicker {
         @Override
-        public Class<?> pick(Class<?> adapterType, Class<?>[] implementationsTypes, Object adaptable) {
+        public Class<?> pick(@NotNull Class<?> adapterType, Class<?> @NotNull [] implementationsTypes, @NotNull Object adaptable) {
             return null;
-        }        
+        }
     }
-    
+
     static final class LastImplementationPicker implements ImplementationPicker {
         @Override
-        public Class<?> pick(Class<?> adapterType, Class<?>[] implementationsTypes, Object adaptable) {
+        public Class<?> pick(@NotNull Class<?> adapterType, Class<?> @NotNull [] implementationsTypes, @NotNull Object adaptable) {
             return implementationsTypes[implementationsTypes.length - 1];
-        }        
+        }
     }
-    
+
 }
diff --git a/src/test/java/org/apache/sling/models/impl/CachingTest.java b/src/test/java/org/apache/sling/models/impl/CachingTest.java
index 1ba37ca..9fc175f 100644
--- a/src/test/java/org/apache/sling/models/impl/CachingTest.java
+++ b/src/test/java/org/apache/sling/models/impl/CachingTest.java
@@ -25,8 +25,6 @@ import static org.mockito.Mockito.when;
 
 import java.util.Collections;
 import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Map;
 
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ValueMap;
@@ -54,7 +52,7 @@ public class CachingTest {
 
     @Mock
     private Resource resource;
-    
+
     private ModelAdapterFactory factory;
 
     @Before
@@ -67,7 +65,7 @@ public class CachingTest {
 
         when(request.getAttribute("testValue")).thenReturn("test");
         requestWrapper = new SlingHttpServletRequestWrapper(request);
-        
+
         ValueMap vm = new ValueMapDecorator(Collections.singletonMap("testValue", "test"));
         when(resource.adaptTo(ValueMap.class)).thenReturn(vm);
     }
@@ -83,7 +81,7 @@ public class CachingTest {
 
         verify(request, times(1)).getAttribute("testValue");
     }
-    
+
     @Test
     public void testCachedClassWithResource() {
         CachedModel cached1 = factory.getAdapter(resource, CachedModel.class);
@@ -107,7 +105,7 @@ public class CachingTest {
 
         verify(request, times(2)).getAttribute("testValue");
     }
-    
+
     @Test
     public void testNoCachedClassWithResource() {
         UncachedModel uncached1 = factory.getAdapter(resource, UncachedModel.class);
@@ -154,7 +152,7 @@ public class CachingTest {
         assertEquals("test", cached2.getTestValue());
 
         verify(request, times(1)).getAttribute("testValue");
-        
+
         // If we clear the request attributes, the sling model is no longer cached
         Enumeration<String> attributeNames = request.getAttributeNames();
         while (attributeNames.hasMoreElements()) {
diff --git a/src/test/java/org/apache/sling/models/impl/ConstructorTest.java b/src/test/java/org/apache/sling/models/impl/ConstructorTest.java
index ec62954..ff7e0de 100644
--- a/src/test/java/org/apache/sling/models/impl/ConstructorTest.java
+++ b/src/test/java/org/apache/sling/models/impl/ConstructorTest.java
@@ -16,8 +16,13 @@
  */
 package org.apache.sling.models.impl;
 
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -63,7 +68,7 @@ public class ConstructorTest {
 
     @Before
     public void setup() {
-        
+
         when(request.getAttribute("attribute")).thenReturn(INT_VALUE);
         when(request.getAttribute("attribute2")).thenReturn(STRING_VALUE);
 
@@ -145,6 +150,7 @@ public class ConstructorTest {
 
         class ModelCreator implements Callable<String> {
             @Override
+            @SuppressWarnings("unused")
             public String call() throws Exception {
                 try {
                     WithOneConstructorModel model = factory.getAdapter(request, WithOneConstructorModel.class);
@@ -190,6 +196,7 @@ public class ConstructorTest {
     }
 
     @Test
+    @SuppressWarnings({ "deprecation", "null" })
     public void testViaInjectionModel() throws Exception {
         Resource suffixResource = mock(Resource.class);
         when(suffixResource.getPath()).thenReturn("/the/suffix");
diff --git a/src/test/java/org/apache/sling/models/impl/InjectorSpecificAnnotationTest.java b/src/test/java/org/apache/sling/models/impl/InjectorSpecificAnnotationTest.java
index 29e7335..b746150 100644
--- a/src/test/java/org/apache/sling/models/impl/InjectorSpecificAnnotationTest.java
+++ b/src/test/java/org/apache/sling/models/impl/InjectorSpecificAnnotationTest.java
@@ -54,6 +54,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @RunWith(MockitoJUnitRunner.class)
+@SuppressWarnings("deprecation")
 public class InjectorSpecificAnnotationTest {
 
     @Mock
@@ -148,6 +149,7 @@ public class InjectorSpecificAnnotationTest {
     }
 
     @Test
+    @SuppressWarnings({ "unchecked", "null" })
     public void testOSGiServiceField() throws InvalidSyntaxException {
         ServiceReference ref = mock(ServiceReference.class);
         Logger log = mock(Logger.class);
@@ -236,6 +238,7 @@ public class InjectorSpecificAnnotationTest {
     }
 
     @Test
+    @SuppressWarnings({ "unchecked", "null" })
     public void testOSGiServiceConstructor() throws InvalidSyntaxException {
         ServiceReference ref = mock(ServiceReference.class);
         Logger log = mock(Logger.class);
diff --git a/src/test/java/org/apache/sling/models/impl/OSGiInjectionTest.java b/src/test/java/org/apache/sling/models/impl/OSGiInjectionTest.java
index 2b8149e..0cae0ae 100644
--- a/src/test/java/org/apache/sling/models/impl/OSGiInjectionTest.java
+++ b/src/test/java/org/apache/sling/models/impl/OSGiInjectionTest.java
@@ -78,6 +78,7 @@ public class OSGiInjectionTest {
     }
 
     @Test
+    @SuppressWarnings({ "unchecked", "null" })
     public void testSimpleOSGiModelField() throws Exception {
         ServiceReference ref = mock(ServiceReference.class);
         ServiceInterface service = mock(ServiceInterface.class);
@@ -96,6 +97,7 @@ public class OSGiInjectionTest {
     }
 
     @Test
+    @SuppressWarnings({ "unchecked", "null", "deprecation" })
     public void testListOSGiModelField() throws Exception {
         ServiceReference ref1 = mock(ServiceReference.class);
         ServiceInterface service1 = mock(ServiceInterface.class);
@@ -120,6 +122,7 @@ public class OSGiInjectionTest {
     }
 
     @Test
+    @SuppressWarnings({ "unchecked", "null", "deprecation" })
     public void testArrayOSGiModelField() throws Exception {
         ServiceReference ref1 = mock(ServiceReference.class);
         ServiceInterface service1 = mock(ServiceInterface.class);
@@ -144,6 +147,7 @@ public class OSGiInjectionTest {
     }
 
     @Test
+    @SuppressWarnings("null")
     public void testOptionalArrayOSGiModelField() throws Exception {
 
         Resource res = mock(Resource.class);
@@ -156,6 +160,7 @@ public class OSGiInjectionTest {
     }
 
     @Test
+    @SuppressWarnings("null")
     public void testOptionalListOSGiModelField() throws Exception {
         Resource res = mock(Resource.class);
 
@@ -167,6 +172,7 @@ public class OSGiInjectionTest {
     }
 
     @Test
+    @SuppressWarnings({ "unchecked", "null", "deprecation" })
     public void testCollectionOSGiModelField() throws Exception {
         ServiceReference ref1 = mock(ServiceReference.class);
         ServiceInterface service1 = mock(ServiceInterface.class);
@@ -191,6 +197,7 @@ public class OSGiInjectionTest {
     }
 
     @Test
+    @SuppressWarnings({ "unused", "unchecked", "null" })
     public void testSetOSGiModelField() throws Exception {
         ServiceReference ref1 = mock(ServiceReference.class);
         ServiceInterface service1 = mock(ServiceInterface.class);
@@ -216,6 +223,7 @@ public class OSGiInjectionTest {
     }
 
     @Test
+    @SuppressWarnings({ "unchecked", "null" })
     public void testSimpleOSGiModelConstructor() throws Exception {
         ServiceReference ref = mock(ServiceReference.class);
         ServiceInterface service = mock(ServiceInterface.class);
@@ -235,6 +243,7 @@ public class OSGiInjectionTest {
     }
 
     @Test
+    @SuppressWarnings({ "deprecation", "unchecked", "null" })
     public void testListOSGiModelConstructor() throws Exception {
         ServiceReference ref1 = mock(ServiceReference.class);
         ServiceInterface service1 = mock(ServiceInterface.class);
diff --git a/src/test/java/org/apache/sling/models/impl/RequestDisposalTest.java b/src/test/java/org/apache/sling/models/impl/RequestDisposalTest.java
index 6967c6d..fea9b97 100644
--- a/src/test/java/org/apache/sling/models/impl/RequestDisposalTest.java
+++ b/src/test/java/org/apache/sling/models/impl/RequestDisposalTest.java
@@ -16,6 +16,24 @@
  */
 package org.apache.sling.models.impl;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.when;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.inject.Inject;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletRequestEvent;
+
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.wrappers.SlingHttpServletRequestWrapper;
@@ -33,20 +51,6 @@ import org.mockito.invocation.InvocationOnMock;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.mockito.stubbing.Answer;
 
-import javax.annotation.Nonnull;
-import javax.inject.Inject;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletRequestEvent;
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Type;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import static org.mockito.Mockito.*;
-import static org.junit.Assert.*;
-
 @RunWith(MockitoJUnitRunner.class)
 public class RequestDisposalTest {
     @Mock
@@ -177,7 +181,7 @@ public class RequestDisposalTest {
 
         @Nullable
         @Override
-        public Object getValue(@Nonnull Object o, String s, @Nonnull Type type, @Nonnull AnnotatedElement annotatedElement, @Nonnull DisposalCallbackRegistry disposalCallbackRegistry) {
+        public Object getValue(@NotNull Object o, String s, @NotNull Type type, @NotNull AnnotatedElement annotatedElement, @NotNull DisposalCallbackRegistry disposalCallbackRegistry) {
             TestDisposalCallback callback = new TestDisposalCallback();
             callbacks.add(callback);
             disposalCallbackRegistry.addDisposalCallback(callback);
diff --git a/src/test/java/org/apache/sling/models/impl/ResourceModelClassesTest.java b/src/test/java/org/apache/sling/models/impl/ResourceModelClassesTest.java
index 96b62b7..bab7029 100644
--- a/src/test/java/org/apache/sling/models/impl/ResourceModelClassesTest.java
+++ b/src/test/java/org/apache/sling/models/impl/ResourceModelClassesTest.java
@@ -166,6 +166,7 @@ public class ResourceModelClassesTest {
         assertEquals("hello", model.getStringList().get(0));
     }
 
+    @SuppressWarnings({ "unused", "null" })
     @Test
     public void testRequiredPropertyModel() {
         Map<String, Object> map = new HashMap<>();
@@ -204,6 +205,7 @@ public class ResourceModelClassesTest {
         verify(vm).get("required", String.class);
     }
 
+    @SuppressWarnings({ "unused", "null" })
     @Test
     public void testRequiredPropertyMissingModelOptionalStrategy() {
         Map<String, Object> map = new HashMap<>();
diff --git a/src/test/java/org/apache/sling/models/impl/ResourceModelInterfacesTest.java b/src/test/java/org/apache/sling/models/impl/ResourceModelInterfacesTest.java
index 6ffcb5e..0b52d56 100644
--- a/src/test/java/org/apache/sling/models/impl/ResourceModelInterfacesTest.java
+++ b/src/test/java/org/apache/sling/models/impl/ResourceModelInterfacesTest.java
@@ -85,6 +85,7 @@ public class ResourceModelInterfacesTest {
     }
 
     @Test
+    @SuppressWarnings({ "unused", "null" })
     public void testRequiredPropertyModel() {
         Map<String, Object> map = new HashMap<>();
         map.put("first", "first-value");
diff --git a/src/test/java/org/apache/sling/models/testutil/ModelAdapterFactoryUtil.java b/src/test/java/org/apache/sling/models/testutil/ModelAdapterFactoryUtil.java
index bd3a133..898a998 100644
--- a/src/test/java/org/apache/sling/models/testutil/ModelAdapterFactoryUtil.java
+++ b/src/test/java/org/apache/sling/models/testutil/ModelAdapterFactoryUtil.java
@@ -44,7 +44,7 @@ import org.osgi.framework.Version;
  * for registering sling model classes in ModelAdapterFactory.
  */
 public final class ModelAdapterFactoryUtil {
-    
+
     private ModelAdapterFactoryUtil() {
         // static methods only
     }
@@ -77,14 +77,14 @@ public final class ModelAdapterFactoryUtil {
         }
 
         @Override
-        public Dictionary getHeaders() {
-            Dictionary<String, Object> headers = new Hashtable<String, Object>();
+        public Dictionary<String,String> getHeaders() {
+            Dictionary<String, String> headers = new Hashtable<>();
             headers.put("Sling-Model-Packages", "dummy.package");
             return headers;
         }
 
         @Override
-        public Enumeration findEntries(String path, String filePattern, boolean recurse) {
+        public Enumeration<URL> findEntries(String path, String filePattern, boolean recurse) {
             Vector<URL> urls = new Vector<>(); // NOPMD
             for (int i = 0; i < classes.length; i++) {
                 try {
@@ -98,7 +98,7 @@ public final class ModelAdapterFactoryUtil {
         }
 
         @Override
-        public Class loadClass(String name) throws ClassNotFoundException {
+        public Class<?> loadClass(String name) throws ClassNotFoundException {
             return getClass().getClassLoader().loadClass(name);
         }
 
@@ -153,12 +153,12 @@ public final class ModelAdapterFactoryUtil {
         }
 
         @Override
-        public ServiceReference[] getRegisteredServices() { // NOPMD
+        public ServiceReference<?>[] getRegisteredServices() { // NOPMD
             return null;
         }
 
         @Override
-        public ServiceReference[] getServicesInUse() { // NOPMD
+        public ServiceReference<?>[] getServicesInUse() { // NOPMD
             return null;
         }
 
@@ -173,7 +173,7 @@ public final class ModelAdapterFactoryUtil {
         }
 
         @Override
-        public Dictionary getHeaders(String locale) {
+        public Dictionary<String,String> getHeaders(String locale) {
             return null;
         }
 
@@ -183,12 +183,12 @@ public final class ModelAdapterFactoryUtil {
         }
 
         @Override
-        public Enumeration getResources(String name) throws IOException {
+        public Enumeration<URL> getResources(String name) throws IOException {
             return null;
         }
 
         @Override
-        public Enumeration getEntryPaths(String path) {
+        public Enumeration<String> getEntryPaths(String path) {
             return null;
         }