Skip to content

Commit 1f407d2

Browse files
authored
Merge pull request #1649 from PavlidisLab/copilot/fix-blacklisted-entity-search-error
Fix BeanInstantiationException when searching for blacklisted entities
2 parents bd1ca1f + f489643 commit 1f407d2

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

gemma-core/src/main/java/ubic/gemma/persistence/util/EntityUrlBuilder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import ubic.gemma.model.genome.Taxon;
2727

2828
import javax.annotation.Nullable;
29+
import java.lang.reflect.Modifier;
2930
import java.net.URI;
3031
import java.util.Collection;
3132
import java.util.List;
@@ -105,6 +106,9 @@ public <T extends Identifiable> EntityUrl<T> entity( T entity ) {
105106
}
106107

107108
public <T extends Identifiable> EntityUrl<T> entity( Class<T> entityType, Long id ) {
109+
if ( Modifier.isAbstract( entityType.getModifiers() ) ) {
110+
throw new UnsupportedEntityUrlException( "Cannot generate a URL for abstract entity type " + entityType.getSimpleName() + ".", entityType );
111+
}
108112
T entity = BeanUtils.instantiate( entityType );
109113
if ( entity instanceof AbstractIdentifiable ) {
110114
( ( AbstractIdentifiable ) entity ).setId( id );

gemma-core/src/test/java/ubic/gemma/persistence/util/EntityUrlBuilderTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ubic.gemma.persistence.util;
22

33
import org.junit.Test;
4+
import ubic.gemma.model.blacklist.BlacklistedEntity;
45
import ubic.gemma.model.common.description.Characteristic;
56
import ubic.gemma.model.expression.arrayDesign.ArrayDesign;
67
import ubic.gemma.model.expression.experiment.ExpressionExperiment;
@@ -81,4 +82,9 @@ public void testFactorValueOntologyUrl() {
8182
c.setValueUri( "http://purl.obolibrary.org/ont/NCBITaxon_9606" );
8283
assertThrows( UnsupportedEntityUrlException.class, () -> entityUrlBuilder.fromHostUrl().entity( c ).ont().toUriString() );
8384
}
85+
86+
@Test
87+
public void testAbstractEntityType() {
88+
assertThrows( UnsupportedEntityUrlException.class, () -> entityUrlBuilder.fromHostUrl().entity( BlacklistedEntity.class, 1L ) );
89+
}
8490
}

0 commit comments

Comments
 (0)