Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HqdmObjectFactory NPE Fix #103

Merged
merged 8 commits into from
Jan 27, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
#102 Fix NPE in HqdmObjectFactory
twalmsley committed Jan 16, 2023
commit aed706b087db7e2c411fadddf8ce30e876d12b89
Original file line number Diff line number Diff line change
@@ -18,8 +18,10 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import uk.gov.gchq.magmacore.hqdm.exception.HqdmException;
@@ -65,7 +67,7 @@ public static <T extends Thing> T create(final HqdmIri hqdmType, final IRI iri)
*/
public static Thing create(final IRI iri, final List<Pair<Object, Object>> pairs) throws HqdmException {
try {
final List<IRI> iris = new ArrayList<>();
final Set<IRI> iris = new HashSet<>();
for (final Pair<Object, Object> pair : pairs.stream()
.filter(pair -> pair.getLeft().equals(RDF_TYPE))
.filter(pair -> pair.getRight().toString().startsWith(HQDM.HQDM.getNamespace()))
@@ -77,7 +79,7 @@ public static Thing create(final IRI iri, final List<Pair<Object, Object>> pairs
final Thing result;

if (iris.size() == 1) {
result = mapToThing(iris.get(0).getResource(), iri);
result = mapToThing(iris.iterator().next().getResource(), iri);
} else {
result = DynamicObjects.create(iri.toString(), Thing.class, irisToClasses(iris));
}
@@ -104,7 +106,7 @@ public static Thing create(final IRI iri, final List<Pair<Object, Object>> pairs
* @param iris List of {@link IRI}.
* @return Array of Class.
*/
private static <T extends Thing> java.lang.Class<T>[] irisToClasses(final List<IRI> iris) {
private static <T extends Thing> java.lang.Class<T>[] irisToClasses(final Set<IRI> iris) {
final List<java.lang.Class<? extends Thing>> classes = new ArrayList<>(3);

// It will be a small list so just iterate it.
Original file line number Diff line number Diff line change
@@ -57,12 +57,7 @@ public static <T extends Thing, U extends Thing> U create(final String id, final
*/
public static <T extends Thing, U extends Thing> U implementInterfaces(final T thing,
final java.lang.Class<U> returnType, final java.lang.Class<T>[] classes) {
try {
return (U) Proxy.newProxyInstance(ClassServices.class.getClassLoader(), classes, new ThingHandler(thing));

} catch (final Exception e) {
return null;
}
return (U) Proxy.newProxyInstance(ClassServices.class.getClassLoader(), classes, new ThingHandler(thing));
}

/**