Buggy code:
public BaseObject getXObject ( DocumentReference classReference , boolean create , XWikiContext context ) { } @ Deprecated public BaseObject getObject ( String className , boolean create , XWikiContext context ) { } public boolean validate ( XWikiContext context ) throws XWikiException { } public boolean validate ( String [ ] classNames , XWikiContext context ) throws XWikiException { } public static void backupContext ( Map < String , Object > backup , XWikiContext context ) { } public static void restoreContext ( Map < String , Object > backup , XWikiContext context ) { } public void setAsContextDoc ( XWikiContext context ) { } public String getPreviousVersion ( ) { } @ Override public String toString ( ) { } public void setHidden ( Boolean hidden ) { } public Boolean isHidden ( ) { } public void convertSyntax ( String targetSyntaxId , XWikiContext context ) throws XWikiException { } public void convertSyntax ( Syntax targetSyntax , XWikiContext context ) throws XWikiException { } public XDOM getXDOM ( ) { } public boolean is10Syntax ( ) { } public boolean is10Syntax ( String syntaxId ) { } private void init ( DocumentReference reference ) { } private boolean executeValidationScript ( XWikiContext context , String validationScript ) throws XWikiException { } private static String performSyntaxConversion ( String content , String source , Syntax targetSyntax , TransformationContext txContext ) throws XWikiException { } private static String performSyntaxConversion ( String content , String source , String currentSyntaxId , Syntax targetSyntax ) throws XWikiException { } private static String performSyntaxConversion ( XDOM content , Syntax targetSyntax , TransformationContext txContext ) throws XWikiException { } private static String renderXDOM ( XDOM content , Syntax targetSyntax ) throws XWikiException { } private XDOM parseContent ( String content ) throws XWikiException { } private static XDOM parseContent ( String syntaxId , String content , String source ) throws XWikiException { } private Syntax getDefaultDocumentSyntax ( ) { } private String serializeReference ( DocumentReference reference , EntityReferenceSerializer < String > serializer , DocumentReference defaultReference ) { } public DocumentReference resolveClassReference ( String documentName ) { } private DocumentReference resolveClassReference ( EntityReference reference ) { } protected EntityReference getRelativeParentReference ( ) { } private BaseObject prepareXObject ( EntityReference classReference ) { } public MergeResult merge ( XWikiDocument previousDocument , XWikiDocument newDocument , MergeConfiguration configuration , XWikiContext context ) { } public boolean apply ( XWikiDocument document ) { boolean modified = false ; if ( ! ( StringUtils . equals ( getComment ( ) , document . getContent ( ) ) ) ) { setContent ( document . getContent ( ) ) ; modified = true ; } if ( ObjectUtils . notEqual ( getSyntax ( ) , document . getSyntax ( ) ) ) { setSyntax ( document . getSyntax ( ) ) ; modified = true ; } if ( ! ( StringUtils . equals ( getTitle ( ) , document . getTitle ( ) ) ) ) { setTitle ( document . getTitle ( ) ) ; modified = true ; } if ( ! ( StringUtils . equals ( getFormat ( ) , document . getFormat ( ) ) ) ) { setFormat ( document . getFormat ( ) ) ; modified = true ; } if ( ! ( StringUtils . equals ( getMeta ( ) , document . getMeta ( ) ) ) ) { setMeta ( document . getMeta ( ) ) ; modified = true ; } if ( ! ( StringUtils . equals ( getDefaultTemplate ( ) , document . getDefaultTemplate ( ) ) ) ) { setDefaultTemplate ( document . getDefaultTemplate ( ) ) ; modified = true ; } if ( ObjectUtils . notEqual ( getTemplateDocumentReference ( ) , document . getTemplateDocumentReference ( ) ) ) { setTemplateDocumentReference ( document . getTemplateDocumentReference ( ) ) ; modified = true ; } if ( ObjectUtils . notEqual ( getRelativeParentReference ( ) , document . getRelativeParentReference ( ) ) ) { setParentReference ( document . getRelativeParentReference ( ) ) ; modified = true ; } if ( ! ( StringUtils . equals ( getValidationScript ( ) , document . getValidationScript ( ) ) ) ) { setValidationScript ( document . getValidationScript ( ) ) ; modified = true ; } if ( ( isHidden ( ) ) != ( document . isHidden ( ) ) ) { setHidden ( document . isHidden ( ) ) ; modified = true ; } if ( ! ( StringUtils . equals ( getCustomClass ( ) , document . getCustomClass ( ) ) ) ) { setCustomClass ( document . getCustomClass ( ) ) ; modified = true ; } if ( ObjectUtils . notEqual ( getXClass ( ) , document . getXClass ( ) ) ) { setXClass ( document . getXClass ( ) . clone ( ) ) ; setXClassXML ( document . getXClassXML ( ) ) ; modified = true ; } for ( List < BaseObject > objects : getXObjects ( ) . values ( ) ) { for ( BaseObject originalObj : new ArrayList < BaseObject > ( objects ) ) { if ( originalObj != null ) { BaseObject newObj = document . getXObject ( originalObj . getXClassReference ( ) , originalObj . getNumber ( ) ) ; if ( newObj == null ) { removeXObject ( originalObj ) ; modified = true ; } } } } for ( List < BaseObject > objects : document . getXObjects ( ) . values ( ) ) { for ( BaseObject newObj : objects ) { if ( newObj != null ) { <START_BUG> BaseObject originalObj = document . getXObject ( newObj . getXClassReference ( ) , newObj . getNumber ( ) ) ; <END_BUG> if ( ObjectUtils . notEqual ( newObj , originalObj ) ) { setXObject ( newObj . getNumber ( ) , newObj ) ; modified = true ; } } } } return modified ; } }

Fix:
BaseObject originalObj = getXObject ( newObj . getXClassReference ( ) , newObj . getNumber ( ) ) ;