Buggy code:
public class UnpublishInvalidMetadataJob extends QuartzJobBean implements Service { public static final String UNPUBLISH_LOG = ( Geonet . GEONETWORK ) + ".unpublish" ; @ Autowired XmlSerializer xmlSerializer ; @ Autowired private ConfigurableApplicationContext context ; @ Autowired private ServiceManager serviceManager ; @ Autowired private OperationAllowedRepository operationAllowedRepository ; static final String AUTOMATED_ENTITY = "Automated" ; AtomicBoolean running = new AtomicBoolean ( false ) ; @ Override public void init ( Path appPath , ServiceConfig params ) throws Exception { } @ Override protected void executeInternal ( JobExecutionContext jobContext ) throws JobExecutionException { } @ Override public Element exec ( Element params , ServiceContext context ) throws Exception { } private void performJob ( ServiceContext serviceContext ) throws Exception { } private boolean checkIfNeedsUnpublishingAndSavePublishedRecord ( ServiceContext context , Metadata metadataRecord , DataManager dataManager ) throws Exception { String id = "" + ( metadataRecord . getId ( ) ) ; Element md = xmlSerializer . selectNoXLinkResolver ( String . valueOf ( metadataRecord . getId ( ) ) , true ) ; String schema = metadataRecord . getDataInfo ( ) . getSchemaId ( ) ; PublishRecord todayRecord ; boolean published = UnpublishInvalidMetadataJob . isPublished ( id , context ) ; if ( published ) { <START_BUG> Element report = dataManager . doValidate ( null , schema , id , md , "eng" , false , true ) . one ( ) ; <END_BUG> Pair < String , String > failureReport = failureReason ( context , report ) ; String failureRule = failureReport . one ( ) ; String failureReasons = failureReport . two ( ) ; if ( ! ( failureRule . isEmpty ( ) ) ) { boolean validated = false ; String entity = UnpublishInvalidMetadataJob . AUTOMATED_ENTITY ; published = false ; todayRecord = new PublishRecord ( ) ; todayRecord . setChangedate ( new Date ( ) ) ; todayRecord . setChangetime ( new Date ( ) ) ; todayRecord . setFailurereasons ( failureReasons ) ; todayRecord . setFailurerule ( failureRule ) ; todayRecord . setUuid ( metadataRecord . getUuid ( ) ) ; todayRecord . setEntity ( entity ) ; todayRecord . setPublished ( published ) ; todayRecord . setValidated ( Validity . fromBoolean ( validated ) ) ; context . getBean ( PublishRecordRepository . class ) . save ( todayRecord ) ; final Specifications < OperationAllowed > publicOps = Specifications . where ( isPublic ( view ) ) . or ( isPublic ( download ) ) . or ( isPublic ( editing ) ) . or ( isPublic ( featured ) ) . or ( isPublic ( dynamic ) ) ; operationAllowedRepository . deleteAll ( Specifications . where ( hasMetadataId ( metadataRecord . getId ( ) ) ) . and ( publicOps ) ) ; return true ; } } return false ; } public static boolean isPublished ( String id , ServiceContext context ) throws SQLException { } private Pair < String , String > failureReason ( ServiceContext context , Element report ) { } private void processXsdError ( Element report , StringBuilder rules , StringBuilder failures ) { } private void processSchematronError ( Element report , StringBuilder rules , StringBuilder failures ) { } @ SuppressWarnings ( "unchecked" ) private List < Metadata > lookUpMetadataIds ( MetadataRepository repo ) throws SQLException { } @ SuppressWarnings ( "unchecked" ) static List < PublishRecord > values ( ServiceContext context , int startOffset , int endOffset ) throws Exception { } static class ErrorFinder implements Filter { private static final long serialVersionUID = 1L ; @ Override public boolean matches ( Object obj ) { } } static class ReportFinder implements Filter { private static final long serialVersionUID = 1L ; @ Override public boolean matches ( Object obj ) { } } }

Fix:
Element report = dataManager . doValidate ( context , schema , id , md , "eng" , false , true ) . one ( ) ;