From aab86f578ff0c108eed4ec48069d54dd75bce3ce Mon Sep 17 00:00:00 2001 From: Pascal Brogle Date: Thu, 25 Feb 2016 21:25:19 +0100 Subject: [PATCH] add dummy introspector and use it if java.beans.Introspector is not available fixes crash on android --- .../diff/introspection/DummyIntrospector.java | 34 +++++++++++++++++++ .../introspection/IntrospectionService.java | 11 +++++- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/main/java/de/danielbechler/diff/introspection/DummyIntrospector.java diff --git a/src/main/java/de/danielbechler/diff/introspection/DummyIntrospector.java b/src/main/java/de/danielbechler/diff/introspection/DummyIntrospector.java new file mode 100644 index 00000000..5345615b --- /dev/null +++ b/src/main/java/de/danielbechler/diff/introspection/DummyIntrospector.java @@ -0,0 +1,34 @@ +/* + * Copyright 2014 Daniel Bechler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package de.danielbechler.diff.introspection; + +import de.danielbechler.diff.instantiation.TypeInfo; +import de.danielbechler.util.Assert; + +/** + * Does not attempt to resolve any accessor of the given type. + * + * @author Pascal Brogle + */ +public class DummyIntrospector implements de.danielbechler.diff.introspection.Introspector +{ + public TypeInfo introspect(final Class type) + { + Assert.notNull(type, "type"); + return new TypeInfo(type); + } +} diff --git a/src/main/java/de/danielbechler/diff/introspection/IntrospectionService.java b/src/main/java/de/danielbechler/diff/introspection/IntrospectionService.java index 35eaef62..ff5279e5 100644 --- a/src/main/java/de/danielbechler/diff/introspection/IntrospectionService.java +++ b/src/main/java/de/danielbechler/diff/introspection/IntrospectionService.java @@ -39,13 +39,22 @@ public class IntrospectionService implements IntrospectionConfigurer, IsIntrospe private final NodePathValueHolder nodePathIntrospectorHolder = new NodePathValueHolder(); private final NodePathValueHolder nodePathIntrospectionModeHolder = new NodePathValueHolder(); private final ObjectDifferBuilder objectDifferBuilder; - private Introspector defaultIntrospector = new StandardIntrospector(); + private Introspector defaultIntrospector; private InstanceFactory instanceFactory = new PublicNoArgsConstructorInstanceFactory(); private PropertyAccessExceptionHandler defaultPropertyAccessExceptionHandler = new DefaultPropertyAccessExceptionHandler(); public IntrospectionService(final ObjectDifferBuilder objectDifferBuilder) { this.objectDifferBuilder = objectDifferBuilder; + try + { + Class.forName("java.beans.Introspector"); + defaultIntrospector = new StandardIntrospector(); + } + catch(final ClassNotFoundException e ) + { + defaultIntrospector = new DummyIntrospector(); + } } public boolean isIntrospectable(final DiffNode node)