Buggy code:
protected static final String ENTITY_RESOLVER = ( Constants . XERCES_PROPERTY_PREFIX ) + ( Constants . ENTITY_RESOLVER_PROPERTY ) ; private static final String [ ] RECOGNIZED_FEATURES = new String [ ] { XMLDocumentFragmentScannerImpl . NAMESPACES , VALIDATION , XMLDocumentFragmentScannerImpl . NOTIFY_BUILTIN_REFS , NOTIFY_CHAR_REFS } ; private static final Boolean [ ] FEATURE_DEFAULTS = new Boolean [ ] { null , null , Boolean . FALSE , Boolean . FALSE } ; private static final String [ ] RECOGNIZED_PROPERTIES = new String [ ] { SYMBOL_TABLE , ERROR_REPORTER , ENTITY_MANAGER , XMLDocumentFragmentScannerImpl . ENTITY_RESOLVER } ; private static final Object [ ] PROPERTY_DEFAULTS = new Object [ ] { null , null , null , null } ; private static final boolean DEBUG_SCANNER_STATE = false ; private static final boolean DEBUG_DISPATCHER = false ; protected static final boolean DEBUG_CONTENT_SCANNING = false ; protected XMLDocumentHandler fDocumentHandler ; protected int [ ] fEntityStack = new int [ 4 ] ; protected int fMarkupDepth ; protected int fScannerState ; protected boolean fInScanContent = false ; protected boolean fHasExternalDTD ; protected boolean fStandalone ; protected ExternalSubsetResolver fExternalSubsetResolver ; protected QName fCurrentElement ; protected XMLDocumentFragmentScannerImpl . ElementStack fElementStack = new XMLDocumentFragmentScannerImpl . ElementStack ( ) ; protected boolean fNotifyBuiltInRefs = false ; protected XMLDocumentFragmentScannerImpl . Dispatcher fDispatcher ; protected XMLDocumentFragmentScannerImpl . Dispatcher fContentDispatcher = createContentDispatcher ( ) ; protected final QName fElementQName = new QName ( ) ; protected final QName fAttributeQName = new QName ( ) ; protected final XMLAttributesImpl fAttributes = new XMLAttributesImpl ( ) ; protected final XMLString fTempString = new XMLString ( ) ; protected final XMLString fTempString2 = new XMLString ( ) ; private final String [ ] fStrings = new String [ 3 ] ; private final XMLStringBuffer fStringBuffer = new XMLStringBuffer ( ) ; private final XMLStringBuffer fStringBuffer2 = new XMLStringBuffer ( ) ; private final QName fQName = new QName ( ) ; private final char [ ] fSingleChar = new char [ 1 ] ; private final ExternalEntity fExternalEntity = new XMLEntityManager . ExternalEntity ( ) ; private boolean fSawSpace ; private Augmentations fTempAugmentations = null ; public XMLDocumentFragmentScannerImpl ( ) { } public void setInputSource ( XMLInputSource inputSource ) throws IOException { } public boolean scanDocument ( boolean complete ) throws IOException , XNIException { } public void reset ( XMLComponentManager componentManager ) throws XMLConfigurationException { } public String [ ] getRecognizedFeatures ( ) { } public void setFeature ( String featureId , boolean state ) throws XMLConfigurationException { } public String [ ] getRecognizedProperties ( ) { } public void setProperty ( String propertyId , Object value ) throws XMLConfigurationException { } public Boolean getFeatureDefault ( String featureId ) { } public Object getPropertyDefault ( String propertyId ) { } public void setDocumentHandler ( XMLDocumentHandler documentHandler ) { } public XMLDocumentHandler getDocumentHandler ( ) { } public void startEntity ( String name , XMLResourceIdentifier identifier , String encoding , Augmentations augs ) throws XNIException { } public void endEntity ( String name , Augmentations augs ) throws XNIException { } protected XMLDocumentFragmentScannerImpl . Dispatcher createContentDispatcher ( ) { } protected void scanXMLDeclOrTextDecl ( boolean scanningTextDecl ) throws IOException , XNIException { super . scanXMLDeclOrTextDecl ( scanningTextDecl , fStrings ) ; ( fMarkupDepth ) -- ; String version = fStrings [ 0 ] ; String encoding = fStrings [ 1 ] ; String standalone = fStrings [ 2 ] ; fStandalone = ( standalone != null ) && ( standalone . equals ( "yes" ) ) ; fEntityManager . setStandalone ( fStandalone ) ; fEntityScanner . setXMLVersion ( version ) ; if ( ( fDocumentHandler ) != null ) { if ( scanningTextDecl ) { fDocumentHandler . textDecl ( version , encoding , null ) ; } else { fDocumentHandler . xmlDecl ( version , encoding , standalone , null ) ; } } <START_BUG> if ( ( encoding != null ) && ( ! ( fCurrentEntity . isDeclaredEncoding ( ) ) ) ) { <END_BUG> fEntityScanner . setEncoding ( encoding ) ; } } protected void scanPIData ( String target , XMLString data ) throws IOException , XNIException { } protected void scanComment ( ) throws IOException , XNIException { } protected boolean scanStartElement ( ) throws IOException , XNIException { } protected void scanStartElementName ( ) throws IOException , XNIException { } protected boolean scanStartElementAfterName ( ) throws IOException , XNIException { } protected void scanAttribute ( XMLAttributes attributes ) throws IOException , XNIException { } protected int scanContent ( ) throws IOException , XNIException { } protected boolean scanCDATASection ( boolean complete ) throws IOException , XNIException { } protected int scanEndElement ( ) throws IOException , XNIException { } protected void scanCharReference ( ) throws IOException , XNIException { } protected void scanEntityReference ( ) throws IOException , XNIException { } private void handleCharacter ( char c , String entity ) throws XNIException { } protected int handleEndElement ( QName element , boolean isEmpty ) throws XNIException { } protected final void setScannerState ( int state ) { } protected final void setDispatcher ( XMLDocumentFragmentScannerImpl . Dispatcher dispatcher ) { } protected String getScannerStateName ( int state ) { } public String getDispatcherName ( XMLDocumentFragmentScannerImpl . Dispatcher dispatcher ) { } protected static class ElementStack { protected QName [ ] fElements ; protected int fSize ; public ElementStack ( ) { } public QName pushElement ( QName element ) { } public void popElement ( QName element ) { } public void clear ( ) { } } protected interface Dispatcher { public boolean dispatch ( boolean complete ) throws IOException , XNIException { } } protected class FragmentContentDispatcher implements XMLDocumentFragmentScannerImpl . Dispatcher { public boolean dispatch ( boolean complete ) throws IOException , XNIException { } protected boolean scanForDoctypeHook ( ) throws IOException , XNIException { } protected boolean elementDepthIsZeroHook ( ) throws IOException , XNIException { } protected boolean scanRootElementHook ( ) throws IOException , XNIException { }

Fix:
if ( ( encoding != null ) && ( ! ( fCurrentEntity . isEncodingExternallySpecified ( ) ) ) ) {