Skip to content

Commit cab2ace

Browse files
committed
Fix more potential NPE and add @nullable annotations
1 parent d50296b commit cab2ace

9 files changed

Lines changed: 28 additions & 29 deletions

src/ubic/basecode/ontology/jena/AbstractOntologyService.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public abstract class AbstractOntologyService implements OntologyService {
9191
private Map<String, String> alternativeIDs;
9292
@Nullable
9393
private SearchIndex index;
94+
@Nullable
9495
private Set<Restriction> additionalRestrictions;
9596
private boolean isInitialized = false;
9697
@Nullable
@@ -740,8 +741,10 @@ private void initSearchByAlternativeId() {
740741
// for all Ontology terms that exist in the tree
741742
ExtendedIterator<OntClass> iterator = model.listClasses();
742743
while ( iterator.hasNext() ) {
743-
OntClass ind = iterator.next();
744-
OntologyTerm ontologyTerm = new OntologyTermImpl( ind, additionalRestrictions );
744+
OntologyTerm ontologyTerm = new OntologyTermImpl( iterator.next(), additionalRestrictions );
745+
if ( ontologyTerm.getUri() == null ) {
746+
continue;
747+
}
745748
// lets find the baseUri, to change to valueUri
746749
String baseOntologyUri = ontologyTerm.getUri().substring( 0, ontologyTerm.getUri().lastIndexOf( "/" ) + 1 );
747750
for ( String alternativeId : ontologyTerm.getAlternativeIds() ) {

src/ubic/basecode/ontology/jena/OntologyCardinalityRestrictionImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.hp.hpl.jena.ontology.Restriction;
2222
import ubic.basecode.ontology.model.OntologyCardinalityRestriction;
2323

24+
import javax.annotation.Nullable;
2425
import java.util.Set;
2526

2627
/**
@@ -32,7 +33,7 @@ class OntologyCardinalityRestrictionImpl extends OntologyRestrictionImpl impleme
3233
private final int cardinality;
3334
private final CardinalityType cardType;
3435

35-
public OntologyCardinalityRestrictionImpl( Restriction resource, Set<Restriction> additionalRestrictions ) {
36+
public OntologyCardinalityRestrictionImpl( Restriction resource, @Nullable Set<Restriction> additionalRestrictions ) {
3637
super( resource, additionalRestrictions );
3738

3839
if ( resource.isMaxCardinalityRestriction() ) {

src/ubic/basecode/ontology/jena/OntologyClassRestrictionImpl.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,12 @@
1818
*/
1919
package ubic.basecode.ontology.jena;
2020

21-
import com.hp.hpl.jena.ontology.AllValuesFromRestriction;
22-
import com.hp.hpl.jena.ontology.HasValueRestriction;
23-
import com.hp.hpl.jena.ontology.OntClass;
24-
import com.hp.hpl.jena.ontology.OntProperty;
25-
import com.hp.hpl.jena.ontology.Restriction;
26-
import com.hp.hpl.jena.ontology.SomeValuesFromRestriction;
21+
import com.hp.hpl.jena.ontology.*;
2722
import com.hp.hpl.jena.rdf.model.RDFNode;
2823
import ubic.basecode.ontology.model.OntologyClassRestriction;
2924
import ubic.basecode.ontology.model.OntologyTerm;
3025

26+
import javax.annotation.Nullable;
3127
import java.util.Set;
3228

3329
/**
@@ -38,7 +34,7 @@ class OntologyClassRestrictionImpl extends OntologyRestrictionImpl implements On
3834
private final OntologyTerm restrictedTo;
3935
private final Set<Restriction> additionalRestrictions;
4036

41-
public OntologyClassRestrictionImpl( Restriction term, Set<Restriction> additionalRestrictions ) {
37+
public OntologyClassRestrictionImpl( Restriction term, @Nullable Set<Restriction> additionalRestrictions ) {
4238
super( term, additionalRestrictions );
4339
this.additionalRestrictions = additionalRestrictions;
4440

src/ubic/basecode/ontology/jena/OntologyDatatypeRestrictionImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
package ubic.basecode.ontology.jena;
2020

2121
import com.hp.hpl.jena.ontology.Restriction;
22-
import com.hp.hpl.jena.rdf.model.Property;
2322
import ubic.basecode.ontology.model.OntologyDatatypeRestriction;
2423

24+
import javax.annotation.Nullable;
2525
import java.util.Set;
2626

2727
/**
@@ -31,8 +31,8 @@ class OntologyDatatypeRestrictionImpl extends OntologyRestrictionImpl implements
3131

3232
private final Class<?> type;
3333

34-
public OntologyDatatypeRestrictionImpl( Restriction resource, Set<Restriction> additionalRestrcitions ) {
35-
super( resource, additionalRestrcitions );
34+
public OntologyDatatypeRestrictionImpl( Restriction resource, @Nullable Set<Restriction> additionalRestrictions ) {
35+
super( resource, additionalRestrictions );
3636
assert restrictionOn != null;
3737
this.type = PropertyFactory.convertType( resource.getOnProperty().asDatatypeProperty() );
3838
}

src/ubic/basecode/ontology/jena/OntologyIndividualImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import ubic.basecode.ontology.model.OntologyIndividual;
2929
import ubic.basecode.ontology.model.OntologyTerm;
3030

31+
import javax.annotation.Nullable;
3132
import java.util.Set;
3233

3334
/**
@@ -38,13 +39,13 @@ class OntologyIndividualImpl extends AbstractOntologyResource implements Ontolog
3839
private final Individual ind;
3940
private final Set<Restriction> additionalRestrictions;
4041

41-
public OntologyIndividualImpl( Individual ind, Set<Restriction> additionalRestrictions ) {
42+
public OntologyIndividualImpl( Individual ind, @Nullable Set<Restriction> additionalRestrictions ) {
4243
super( ind );
4344
this.ind = ind;
4445
this.additionalRestrictions = additionalRestrictions;
4546
}
4647

47-
public OntologyIndividualImpl( Individual ind, Set<Restriction> additionalRestrictions, double score ) {
48+
public OntologyIndividualImpl( Individual ind, @Nullable Set<Restriction> additionalRestrictions, double score ) {
4849
super( ind, score );
4950
this.ind = ind;
5051
this.additionalRestrictions = additionalRestrictions;

src/ubic/basecode/ontology/jena/OntologyRestrictionImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
package ubic.basecode.ontology.jena;
2020

2121
import com.hp.hpl.jena.ontology.Restriction;
22-
import com.hp.hpl.jena.rdf.model.Property;
2322
import ubic.basecode.ontology.model.OntologyProperty;
2423
import ubic.basecode.ontology.model.OntologyRestriction;
2524

25+
import javax.annotation.Nullable;
2626
import java.util.Set;
2727

2828
/**
@@ -34,7 +34,7 @@ abstract class OntologyRestrictionImpl extends OntologyTermImpl implements Ontol
3434

3535
protected OntologyProperty restrictionOn;
3636

37-
public OntologyRestrictionImpl( Restriction resource, Set<Restriction> additionalRestrictions ) {
37+
public OntologyRestrictionImpl( Restriction resource, @Nullable Set<Restriction> additionalRestrictions ) {
3838
super( resource, additionalRestrictions );
3939
this.restrictionOn = PropertyFactory.asProperty( resource.getOnProperty(), additionalRestrictions );
4040
}

src/ubic/basecode/ontology/jena/OntologyTermImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public OntologyTermImpl( OntClass resource, @Nullable Set<Restriction> additiona
5959
this.additionalRestrictions = additionalRestrictions;
6060
}
6161

62-
public OntologyTermImpl( OntClass resource, Set<Restriction> additionalRestrictions, double score ) {
62+
public OntologyTermImpl( OntClass resource, @Nullable Set<Restriction> additionalRestrictions, double score ) {
6363
super( resource, score );
6464
this.ontResource = resource;
6565
this.additionalRestrictions = additionalRestrictions;

src/ubic/basecode/ontology/jena/PropertyFactory.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
22
* The basecode project
3-
*
3+
*
44
* Copyright (c) 2007-2019 University of British Columbia
5-
*
5+
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
88
* You may obtain a copy of the License at
@@ -22,24 +22,23 @@
2222
import com.hp.hpl.jena.ontology.OntProperty;
2323
import com.hp.hpl.jena.ontology.OntResource;
2424
import com.hp.hpl.jena.ontology.Restriction;
25-
import com.hp.hpl.jena.rdf.model.Property;
2625

26+
import javax.annotation.Nullable;
2727
import java.util.Set;
2828

2929
/**
3030
* @author pavlidis
31-
*
3231
*/
3332
class PropertyFactory {
3433

3534
/**
3635
* Convert a Jena property.
37-
*
36+
*
3837
* @param property
3938
* @param source
4039
* @return new property or null if it could not be converted.
4140
*/
42-
public static ubic.basecode.ontology.model.OntologyProperty asProperty( OntProperty property, Set<Restriction> additionalRestrictions ) {
41+
public static ubic.basecode.ontology.model.OntologyProperty asProperty( OntProperty property, @Nullable Set<Restriction> additionalRestrictions ) {
4342

4443
if ( property.isObjectProperty() ) {
4544
return new ObjectPropertyImpl( property.asObjectProperty(), additionalRestrictions );

src/ubic/basecode/ontology/jena/RestrictionFactory.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
22
* The basecode project
3-
*
3+
*
44
* Copyright (c) 2007-2019 University of British Columbia
5-
*
5+
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
88
* You may obtain a copy of the License at
@@ -20,18 +20,17 @@
2020

2121
import com.hp.hpl.jena.ontology.OntProperty;
2222
import com.hp.hpl.jena.ontology.Restriction;
23-
import com.hp.hpl.jena.rdf.model.Property;
2423
import ubic.basecode.ontology.model.OntologyRestriction;
2524

25+
import javax.annotation.Nullable;
2626
import java.util.Set;
2727

2828
/**
2929
* @author pavlidis
30-
*
3130
*/
3231
class RestrictionFactory {
3332

34-
public static OntologyRestriction asRestriction( Restriction restriction, Set<Restriction> additionalRestrictions ) {
33+
public static OntologyRestriction asRestriction( Restriction restriction, @Nullable Set<Restriction> additionalRestrictions ) {
3534

3635
OntProperty onProperty = restriction.getOnProperty();
3736

0 commit comments

Comments
 (0)