From: Alexandre Rossi <alexandre.rossi@gmail.com>
Subject: Fix compilation with woodstox <<5
Forwared: not-needed

Index: davmail.git/src/java/com/ctc/wstx/sr/StreamScanner.java
===================================================================
--- davmail.git.orig/src/java/com/ctc/wstx/sr/StreamScanner.java	2018-10-15 16:16:13.902145390 +0200
+++ davmail.git/src/java/com/ctc/wstx/sr/StreamScanner.java	2018-10-15 16:15:52.469808585 +0200
@@ -54,9 +54,10 @@
  * Abstract base class that defines some basic functionality that all
  * Woodstox reader classes (main XML reader, DTD reader) extend from.
  */
+
 public abstract class StreamScanner
-        extends WstxInputData
-        implements InputProblemReporter,
+    extends WstxInputData
+    implements InputProblemReporter,
         InputConfigFlags, ParsingErrorMsgs
 {
 
@@ -87,9 +88,9 @@
     protected final static char CHAR_LOWEST_LEGAL_LOCALNAME_CHAR = '-';
 
     /*
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
     // Character validity constants, structs
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
      */
 
     /**
@@ -106,8 +107,9 @@
     private final static byte[] sCharValidity = new byte[VALID_CHAR_COUNT];
 
     static {
-        // First, since all valid-as-first chars are also valid-as-other chars,
-        // we'll initialize common chars:
+        /* First, since all valid-as-first chars are also valid-as-other chars,
+         * we'll initialize common chars:
+         */
         sCharValidity['_'] = NAME_CHAR_ALL_VALID_B;
         for (int i = 0, last = ('z' - 'a'); i <= last; ++i) {
             sCharValidity['A' + i] = NAME_CHAR_ALL_VALID_B;
@@ -120,7 +122,8 @@
         sCharValidity[0xD7] = NAME_CHAR_INVALID_B;
         sCharValidity[0xF7] = NAME_CHAR_INVALID_B;
 
-        // And then we can proceed with ones only valid-as-other.
+        /* And then we can proceed with ones only valid-as-other.
+         */
         sCharValidity['-'] = NAME_CHAR_VALID_NONFIRST_B;
         sCharValidity['.'] = NAME_CHAR_VALID_NONFIRST_B;
         sCharValidity[0xB7] = NAME_CHAR_VALID_NONFIRST_B;
@@ -134,7 +137,7 @@
      */
     private final static int VALID_PUBID_CHAR_COUNT = 0x80;
     private final static byte[] sPubidValidity = new byte[VALID_PUBID_CHAR_COUNT];
-    //    private final static byte PUBID_CHAR_INVALID_B = (byte) 0;
+//    private final static byte PUBID_CHAR_INVALID_B = (byte) 0;
     private final static byte PUBID_CHAR_VALID_B = (byte) 1;
     static {
         for (int i = 0, last = ('z' - 'a'); i <= last; ++i) {
@@ -173,9 +176,9 @@
     }
 
     /*
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
     // Basic configuration
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
      */
 
     /**
@@ -202,9 +205,9 @@
     protected boolean mCfgReplaceEntities;
 
     /*
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
     // Symbol handling, if applicable
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
      */
 
     final SymbolTable mSymbols;
@@ -223,9 +226,9 @@
     protected String mCurrName;
 
     /*
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
     // Input handling
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
      */
 
     /**
@@ -246,7 +249,7 @@
      * Custom resolver used to handle external entities that are to be expanded
      * by this reader (external param/general entity expander)
      */
-    protected XMLResolver mEntityResolver = null;
+    XMLResolver mEntityResolver = null;
 
     /**
      * This is the current depth of the input stack (same as what input
@@ -259,18 +262,9 @@
      * indicates what was the depth at the point where the currently active
      * input scope/block was started.
      */
-    protected int mCurrDepth;
+    protected int mCurrDepth = 0;
 
-    protected int mInputTopDepth;
-
-    /**
-     * Number of times a parsed general entity has been expanded; used for
-     * (optionally) limiting number of expansion to guard against
-     * denial-of-service attacks like "Billion Laughs".
-     *
-     * @since 4.3
-     */
-    protected int mEntityExpansionCount;
+    protected int mInputTopDepth = 0;
 
     /**
      * Flag that indicates whether linefeeds in the input data are to
@@ -285,12 +279,13 @@
     /**
      * Flag that indicates whether all escaped chars are accepted in XML 1.0.
      */
-    protected boolean mXml10AllowAllEscapedChars;
+    protected boolean mXml10AllowAllEscapedChars = true;
+
 
     /*
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
     // Buffer(s) for local name(s) and text content
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
      */
 
     /**
@@ -300,10 +295,10 @@
     protected char[] mNameBuffer = null;
 
     /*
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
     // Information about starting location of event
     // Reader is pointing to; updated on-demand
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
      */
 
     // // // Location info at point when current token was started
@@ -313,7 +308,7 @@
      * For big (gigabyte-sized) sizes are possible, needs to be long,
      * unlike pointers and sizes related to in-memory buffers.
      */
-    protected long mTokenInputTotal = 0;
+    protected long mTokenInputTotal = 0; 
 
     /**
      * Input row on which current token starts, 1-based
@@ -327,49 +322,50 @@
     protected int mTokenInputCol = 0;
 
     /*
-    ///////////////////////////////////////////////////////////////////////
-    // XML document information (from doc decl if one was found) common to
-    // all entities (main xml document, external DTD subset)
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
+    // XML document information (from doc decl if one
+    // was found) common to all entities (main xml
+    // document, external DTD subset)
+    ///////////////////////////////////////////////////////////
      */
 
     /**
      * Input stream encoding, if known (passed in, or determined by
      * auto-detection); null if not.
      */
-    protected String mDocInputEncoding = null;
+    String mDocInputEncoding = null;
 
     /**
      * Character encoding from xml declaration, if any; null if no
      * declaration, or it didn't specify encoding.
      */
-    protected String mDocXmlEncoding = null;
+    String mDocXmlEncoding = null;
 
     /**
      * XML version as declared by the document; one of constants
      * from {@link XmlConsts} (like {@link XmlConsts#XML_V_10}).
      */
     protected int mDocXmlVersion = XmlConsts.XML_V_UNKNOWN;
-
+    
     /**
      * Cache of internal character entities;
      */
-    protected Map<String,IntEntity> mCachedEntities;
-
+    protected Map mCachedEntities;
+    
     /**
      * Flag for whether or not character references should be treated as entities
      */
     protected boolean mCfgTreatCharRefsAsEntities;
-
+    
     /**
      * Entity reference stream currently points to.
      */
     protected EntityDecl mCurrEntity;
 
     /*
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
     // Life-cycle
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
      */
 
     /**
@@ -390,26 +386,19 @@
         mCfgNsEnabled = (cf & CFG_NAMESPACE_AWARE) != 0;
         mCfgReplaceEntities = (cf & CFG_REPLACE_ENTITY_REFS) != 0;
 
-        // waiting for pull request, see https://github.com/FasterXML/woodstox/pull/56
-        mXml10AllowAllEscapedChars = true;//mConfig.willXml10AllowAllEscapedChars();
-
         mNormalizeLFs = mConfig.willNormalizeLFs();
         mInputBuffer = null;
         mInputPtr = mInputEnd = 0;
         mEntityResolver = res;
-
+        
         mCfgTreatCharRefsAsEntities = mConfig.willTreatCharRefsAsEnts();
-        if (mCfgTreatCharRefsAsEntities) {
-            mCachedEntities = new HashMap<String,IntEntity>();
-        } else {
-            mCachedEntities = Collections.emptyMap();
-        }
+        mCachedEntities = mCfgTreatCharRefsAsEntities ? new HashMap() : Collections.EMPTY_MAP;
     }
 
     /*
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
     // Package API
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
      */
 
     /**
@@ -420,10 +409,11 @@
     protected WstxInputLocation getLastCharLocation()
     {
         return mInput.getLocation(mCurrInputProcessed + mInputPtr - 1,
-                mCurrInputRow, mInputPtr - mCurrInputRowStart);
+                                  mCurrInputRow,
+                                  mInputPtr - mCurrInputRowStart);
     }
 
-    protected URL getSource() throws IOException {
+    protected URL getSource() {
         return mInput.getSource();
     }
 
@@ -432,10 +422,10 @@
     }
 
     /*
-    ///////////////////////////////////////////////////////////////////////
-    // Partial `LocationInfo` implementation (not implemented
+    ///////////////////////////////////////////////////////////
+    // Partial LocationInfo implementation (not implemented
     // by this base class, but is by some sub-classes)
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
      */
 
     /**
@@ -443,30 +433,30 @@
      * apparently needs to be the end of current event, which is the same
      * as the start of the following event (or EOF if that's next).
      */
-    @Override
     public abstract Location getLocation();
 
     public XMLStreamLocation2 getStartLocation()
     {
         // note: +1 is used as columns are 1-based...
-        return mInput.getLocation(mTokenInputTotal,
-                mTokenInputRow, mTokenInputCol + 1);
+        return mInput.getLocation(mTokenInputTotal, mTokenInputRow,
+                                  mTokenInputCol + 1);
     }
 
     public XMLStreamLocation2 getCurrentLocation()
     {
         return mInput.getLocation(mCurrInputProcessed + mInputPtr,
-                mCurrInputRow, mInputPtr - mCurrInputRowStart + 1);
+                                  mCurrInputRow,
+                                  mInputPtr - mCurrInputRowStart + 1);
     }
 
     /*
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
     // InputProblemReporter implementation
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
      */
 
     public WstxException throwWfcException(String msg, boolean deferErrors)
-            throws WstxException
+        throws WstxException
     {
         WstxException ex = constructWfcException(msg);
         if (!deferErrors) {
@@ -475,8 +465,8 @@
         return ex;
     }
 
-    @Override
-    public void throwParseError(String msg) throws XMLStreamException {
+    public void throwParseError(String msg) throws XMLStreamException
+    {
         throwParseError(msg, null, null);
     }
 
@@ -487,40 +477,38 @@
      * Note: public access only because core code in other packages needs
      * to access it.
      */
-    @Override
     public void throwParseError(String format, Object arg, Object arg2)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         String msg = (arg != null || arg2 != null) ?
-                MessageFormat.format(format, new Object[] { arg, arg2 }) : format;
+            MessageFormat.format(format, new Object[] { arg, arg2 }) : format;
         throw constructWfcException(msg);
     }
 
     public void reportProblem(String probType, String format, Object arg, Object arg2)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         XMLReporter rep = mConfig.getXMLReporter();
         if (rep != null) {
             _reportProblem(rep, probType,
-                    MessageFormat.format(format, new Object[] { arg, arg2 }), null);
+                            MessageFormat.format(format, new Object[] { arg, arg2 }), null);
         }
     }
 
-    @Override
     public void reportProblem(Location loc, String probType,
                               String format, Object arg, Object arg2)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         XMLReporter rep = mConfig.getXMLReporter();
         if (rep != null) {
             String msg = (arg != null || arg2 != null) ?
-                    MessageFormat.format(format, new Object[] { arg, arg2 }) : format;
+                MessageFormat.format(format, new Object[] { arg, arg2 }) : format;
             _reportProblem(rep, probType, msg, loc);
         }
     }
 
     protected void _reportProblem(XMLReporter rep, String probType, String msg, Location loc)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         if (loc == null) {
             loc = getLastCharLocation();
@@ -529,7 +517,7 @@
     }
 
     protected void _reportProblem(XMLReporter rep, XMLValidationProblem prob)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         if (rep != null) {
             Location loc = prob.getLocation();
@@ -556,9 +544,8 @@
      * Note: this is the base implementation used for implementing
      * <code>ValidationContext</code>
      */
-    @Override
     public void reportValidationProblem(XMLValidationProblem prob)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         // !!! TBI: Fail-fast vs. deferred modes?
         /* For now let's implement basic functionality: warnings get
@@ -588,37 +575,36 @@
     }
 
     public void reportValidationProblem(String msg, int severity)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         reportValidationProblem(new XMLValidationProblem(getLastCharLocation(),
-                msg, severity));
+                                                         msg, severity));
     }
 
-    @Override
     public void reportValidationProblem(String msg)
-            throws XMLStreamException
+        throws XMLStreamException
     {
-        reportValidationProblem(new XMLValidationProblem(getLastCharLocation(), msg,
-                XMLValidationProblem.SEVERITY_ERROR));
+        reportValidationProblem(new XMLValidationProblem(getLastCharLocation(),
+                                                         msg,
+                                                         XMLValidationProblem.SEVERITY_ERROR));
     }
 
     public void reportValidationProblem(Location loc, String msg)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         reportValidationProblem(new XMLValidationProblem(loc, msg));
     }
 
-    @Override
     public void reportValidationProblem(String format, Object arg, Object arg2)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         reportValidationProblem(MessageFormat.format(format, new Object[] { arg, arg2 }));
     }
 
     /*
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
     // Other error reporting methods
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
      */
 
     protected WstxException constructWfcException(String msg)
@@ -651,23 +637,28 @@
                 getLastCharLocation(), CHAR_NULL);
     }
 
-    protected void throwUnexpectedChar(int i, String msg) throws WstxException
+    protected void throwUnexpectedChar(int i, String msg)
+        throws WstxException
     {
         char c = (char) i;
         String excMsg = "Unexpected character "+getCharDesc(c)+msg;
         throw new WstxUnexpectedCharException(excMsg, getLastCharLocation(), c);
     }
 
-    protected void throwNullChar() throws WstxException {
+    protected void throwNullChar()
+        throws WstxException
+    {
         throw constructNullCharException();
     }
 
-    protected void throwInvalidSpace(int i) throws WstxException {
+    protected void throwInvalidSpace(int i)
+        throws WstxException
+    {
         throwInvalidSpace(i, false);
     }
 
     protected WstxException throwInvalidSpace(int i, boolean deferErrors)
-            throws WstxException
+        throws WstxException
     {
         char c = (char) i;
         WstxException ex;
@@ -687,10 +678,11 @@
     }
 
     protected void throwUnexpectedEOF(String msg)
-            throws WstxException
+        throws WstxException
     {
-        throw new WstxEOFException("Unexpected EOF"+(msg == null ? "" : msg),
-                getLastCharLocation());
+        throw new WstxEOFException("Unexpected EOF"
+                                   +(msg == null ? "" : msg),
+                                   getLastCharLocation());
     }
 
     /**
@@ -700,23 +692,28 @@
      * entity expansion).
      */
     protected void throwUnexpectedEOB(String msg)
-            throws WstxException
+        throws WstxException
     {
-        throw new WstxEOFException("Unexpected end of input block"+(msg == null ? "" : msg),
-                getLastCharLocation());
+        throw new WstxEOFException("Unexpected end of input block"
+                                   +(msg == null ? "" : msg),
+                                   getLastCharLocation());
     }
 
-    protected void throwFromIOE(IOException ioe) throws WstxException {
+    protected void throwFromIOE(IOException ioe)
+        throws WstxException
+    {
         throw new WstxIOException(ioe);
     }
 
     protected void throwFromStrE(XMLStreamException strex)
-            throws WstxException
+        throws WstxException
     {
         if (strex instanceof WstxException) {
             throw (WstxException) strex;
         }
-        throw new WstxException(strex);
+        WstxException newEx = new WstxException(strex);
+        ExceptionUtil.setInitCause(newEx, strex);
+        throw newEx;
     }
 
     /**
@@ -731,14 +728,15 @@
         ExceptionUtil.throwRuntimeException(e);
     }
 
-    protected String tokenTypeDesc(int type) {
+    protected String tokenTypeDesc(int type)
+    {
         return ErrorConsts.tokenTypeDesc(type);
     }
 
     /*
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
     // Input buffer handling
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
      */
 
     /**
@@ -755,8 +753,8 @@
         return mInputEnd - mInputPtr;
     }
 
-    @SuppressWarnings("cast")
-    protected final int getNext() throws XMLStreamException
+    protected final int getNext()
+        throws XMLStreamException
     {
         if (mInputPtr >= mInputEnd) {
             if (!loadMore()) {
@@ -775,9 +773,8 @@
      * This is necessary when checking keywords, since they can never
      * cross input block boundary.
      */
-    @SuppressWarnings("cast")
     protected final int peekNext()
-            throws XMLStreamException
+        throws XMLStreamException
     {
         if (mInputPtr >= mInputEnd) {
             if (!loadMoreFromCurrent()) {
@@ -788,7 +785,7 @@
     }
 
     protected final char getNextChar(String errorMsg)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         if (mInputPtr >= mInputEnd) {
             loadMore(errorMsg);
@@ -805,7 +802,7 @@
      * such markup is not legal.
      */
     protected final char getNextCharFromCurrent(String errorMsg)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         if (mInputPtr >= mInputEnd) {
             loadMoreFromCurrent(errorMsg);
@@ -818,9 +815,8 @@
      * and return either the character following white space, or -1 to
      * indicate EOF (end of the outermost input source)/
      */
-    @SuppressWarnings("cast")
     protected final int getNextAfterWS()
-            throws XMLStreamException
+        throws XMLStreamException
     {
         if (mInputPtr >= mInputEnd) {
             if (!loadMore()) {
@@ -847,7 +843,7 @@
     }
 
     protected final char getNextCharAfterWS(String errorMsg)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         if (mInputPtr >= mInputEnd) {
             loadMore(errorMsg);
@@ -872,13 +868,13 @@
     }
 
     protected final char getNextInCurrAfterWS(String errorMsg)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         return getNextInCurrAfterWS(errorMsg, getNextCharFromCurrent(errorMsg));
     }
 
     protected final char getNextInCurrAfterWS(String errorMsg, char c)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         while (c <= CHAR_SPACE) {
             // Linefeed?
@@ -905,8 +901,8 @@
      *
      * @return True, if passed in char is '\r' and next one is '\n'.
      */
-    protected final boolean skipCRLF(char c)
-            throws XMLStreamException
+    protected final boolean skipCRLF(char c) 
+        throws XMLStreamException
     {
         boolean result;
 
@@ -939,9 +935,9 @@
     protected final void pushback() { --mInputPtr; }
 
     /*
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
     // Sub-class overridable input handling methods
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
      */
 
     /**
@@ -953,8 +949,9 @@
      */
     protected void initInputSource(WstxInputSource newInput, boolean isExt,
                                    String entityId)
-            throws XMLStreamException
+        throws XMLStreamException
     {
+        mInput = newInput;
         // Let's make sure new input will be read next time input is needed:
         mInputPtr = 0;
         mInputEnd = 0;
@@ -962,12 +959,7 @@
          * error reporting etc.
          */
         mInputTopDepth = mCurrDepth;
-
-        // [WSTX-296]: Check for entity expansion depth against configurable limit
-        int entityDepth = mInput.getEntityDepth() + 1;
-        verifyLimit("Maximum entity expansion depth", mConfig.getMaxEntityDepth(), entityDepth);
-        mInput = newInput;
-        mInput.initInputLocation(this, mCurrDepth, entityDepth);
+        mInput.initInputLocation(this, mCurrDepth);
 
         /* 21-Feb-2006, TSa: Linefeeds are NOT normalized when expanding
          *   internal entities (XML, 2.11)
@@ -987,7 +979,7 @@
      *   we reached EOF.
      */
     protected boolean loadMore()
-            throws XMLStreamException
+        throws XMLStreamException
     {
         WstxInputSource input = mInput;
         do {
@@ -996,7 +988,6 @@
              * are still known.
              */
             mCurrInputProcessed += mInputEnd;
-            verifyLimit("Maximum document characters", mConfig.getMaxCharacters(), mCurrInputProcessed);
             mCurrInputRowStart -= mInputEnd;
             int count;
             try {
@@ -1043,7 +1034,7 @@
     }
 
     protected final boolean loadMore(String errorMsg)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         if (!loadMore()) {
             throwUnexpectedEOF(errorMsg);
@@ -1052,12 +1043,11 @@
     }
 
     protected boolean loadMoreFromCurrent()
-            throws XMLStreamException
+        throws XMLStreamException
     {
         // Need to update offsets properly
         mCurrInputProcessed += mInputEnd;
         mCurrInputRowStart -= mInputEnd;
-        verifyLimit("Maximum document characters", mConfig.getMaxCharacters(), mCurrInputProcessed);
         try {
             int count = mInput.readInto(this);
             return (count > 0);
@@ -1067,7 +1057,7 @@
     }
 
     protected final boolean loadMoreFromCurrent(String errorMsg)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         if (!loadMoreFromCurrent()) {
             throwUnexpectedEOB(errorMsg);
@@ -1090,7 +1080,7 @@
      * @return true if there's now enough data; false if not (EOF)
      */
     protected boolean ensureInput(int minAmount)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         int currAmount = mInputEnd - mInputPtr;
         if (currAmount >= minAmount) {
@@ -1104,7 +1094,7 @@
     }
 
     protected void closeAllInput(boolean force)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         WstxInputSource input = mInput;
         while (true) {
@@ -1128,9 +1118,6 @@
         }
     }
 
-    /**
-     * @param curr Input source currently in use
-     */
     protected void throwNullParent(WstxInputSource curr)
     {
         throw new IllegalStateException(ErrorConsts.ERR_INTERNAL);
@@ -1138,9 +1125,9 @@
     }
 
     /*
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
     // Entity resolution
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
      */
 
     /**
@@ -1170,7 +1157,7 @@
      *   entity, or spans input buffer boundary).
      */
     protected int resolveSimpleEntity(boolean checkStd)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         char[] buf = mInputBuffer;
         int ptr = mInputPtr;
@@ -1241,7 +1228,7 @@
              */
             if (c == 'a') { // amp or apos?
                 c = buf[ptr++];
-
+                
                 if (c == 'm') { // amp?
                     if (buf[ptr++] == 'p') {
                         if (ptr < mInputEnd && buf[ptr++] == ';') {
@@ -1316,7 +1303,7 @@
      *   entity, or spans input buffer boundary).
      */
     protected int resolveCharOnlyEntity(boolean checkStd)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         //int avail = inputInBuffer();
         int avail = mInputEnd - mInputPtr;
@@ -1358,40 +1345,40 @@
                 char d = mInputBuffer[mInputPtr+1];
                 if (d == 'm') {
                     if (avail >= 4
-                            && mInputBuffer[mInputPtr+2] == 'p'
-                            && mInputBuffer[mInputPtr+3] == ';') {
+                        && mInputBuffer[mInputPtr+2] == 'p'
+                        && mInputBuffer[mInputPtr+3] == ';') {
                         mInputPtr += 4;
                         return '&';
                     }
                 } else if (d == 'p') {
                     if (avail >= 5
-                            && mInputBuffer[mInputPtr+2] == 'o'
-                            && mInputBuffer[mInputPtr+3] == 's'
-                            && mInputBuffer[mInputPtr+4] == ';') {
+                        && mInputBuffer[mInputPtr+2] == 'o'
+                        && mInputBuffer[mInputPtr+3] == 's'
+                        && mInputBuffer[mInputPtr+4] == ';') {
                         mInputPtr += 5;
                         return '\'';
                     }
                 }
             } else if (c == 'l') {
                 if (avail >= 3
-                        && mInputBuffer[mInputPtr+1] == 't'
-                        && mInputBuffer[mInputPtr+2] == ';') {
+                    && mInputBuffer[mInputPtr+1] == 't'
+                    && mInputBuffer[mInputPtr+2] == ';') {
                     mInputPtr += 3;
                     return '<';
                 }
             } else if (c == 'g') {
                 if (avail >= 3
-                        && mInputBuffer[mInputPtr+1] == 't'
-                        && mInputBuffer[mInputPtr+2] == ';') {
+                    && mInputBuffer[mInputPtr+1] == 't'
+                    && mInputBuffer[mInputPtr+2] == ';') {
                     mInputPtr += 3;
                     return '>';
                 }
             } else if (c == 'q') {
                 if (avail >= 5
-                        && mInputBuffer[mInputPtr+1] == 'u'
-                        && mInputBuffer[mInputPtr+2] == 'o'
-                        && mInputBuffer[mInputPtr+3] == 't'
-                        && mInputBuffer[mInputPtr+4] == ';') {
+                    && mInputBuffer[mInputPtr+1] == 'u'
+                    && mInputBuffer[mInputPtr+2] == 'o'
+                    && mInputBuffer[mInputPtr+3] == 't'
+                    && mInputBuffer[mInputPtr+4] == ';') {
                     mInputPtr += 5;
                     return '"';
                 }
@@ -1408,7 +1395,7 @@
      * mode); which means it's never called from dtd handler.
      */
     protected EntityDecl resolveNonCharEntity()
-            throws XMLStreamException
+        throws XMLStreamException
     {
         //int avail = inputInBuffer();
         int avail = mInputEnd - mInputPtr;
@@ -1450,8 +1437,8 @@
             char d = mInputBuffer[mInputPtr+1];
             if (d == 'm') {
                 if (avail >= 4
-                        && mInputBuffer[mInputPtr+2] == 'p'
-                        && mInputBuffer[mInputPtr+3] == ';') {
+                    && mInputBuffer[mInputPtr+2] == 'p'
+                    && mInputBuffer[mInputPtr+3] == ';') {
                     // If not automatically expanding:
                     //return sEntityAmp;
                     // mInputPtr += 4;
@@ -1459,30 +1446,30 @@
                 }
             } else if (d == 'p') {
                 if (avail >= 5
-                        && mInputBuffer[mInputPtr+2] == 'o'
-                        && mInputBuffer[mInputPtr+3] == 's'
-                        && mInputBuffer[mInputPtr+4] == ';') {
+                    && mInputBuffer[mInputPtr+2] == 'o'
+                    && mInputBuffer[mInputPtr+3] == 's'
+                    && mInputBuffer[mInputPtr+4] == ';') {
                     return null;
                 }
             }
         } else if (c == 'l') {
             if (avail >= 3
-                    && mInputBuffer[mInputPtr+1] == 't'
-                    && mInputBuffer[mInputPtr+2] == ';') {
+                && mInputBuffer[mInputPtr+1] == 't'
+                && mInputBuffer[mInputPtr+2] == ';') {
                 return null;
             }
         } else if (c == 'g') {
             if (avail >= 3
-                    && mInputBuffer[mInputPtr+1] == 't'
-                    && mInputBuffer[mInputPtr+2] == ';') {
+                && mInputBuffer[mInputPtr+1] == 't'
+                && mInputBuffer[mInputPtr+2] == ';') {
                 return null;
             }
         } else if (c == 'q') {
             if (avail >= 5
-                    && mInputBuffer[mInputPtr+1] == 'u'
-                    && mInputBuffer[mInputPtr+2] == 'o'
-                    && mInputBuffer[mInputPtr+3] == 't'
-                    && mInputBuffer[mInputPtr+4] == ';') {
+                && mInputBuffer[mInputPtr+1] == 'u'
+                && mInputBuffer[mInputPtr+2] == 'o'
+                && mInputBuffer[mInputPtr+3] == 't'
+                && mInputBuffer[mInputPtr+4] == ';') {
                 return null;
             }
         }
@@ -1511,7 +1498,7 @@
      *    input source.
      */
     protected int fullyResolveEntity(boolean allowExt)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         char c = getNextCharFromCurrent(SUFFIX_IN_ENTITY_REF);
         // Do we have a (numeric) character entity reference?
@@ -1528,7 +1515,7 @@
         }
 
         String id = parseEntityName(c);
-
+ 
         // Perhaps we have a pre-defined char reference?
         c = id.charAt(0);
         /*
@@ -1581,7 +1568,7 @@
     {
         String cacheKey = new String(originalChars);
 
-        IntEntity entity = mCachedEntities.get(cacheKey);
+        IntEntity entity = (IntEntity) mCachedEntities.get(cacheKey);
         if (entity == null) {
             String repl;
             if (ch <= 0xFFFF) {
@@ -1606,14 +1593,14 @@
      *<p>
      * note: called by sub-classes (dtd parser), needs to be protected.
      *
-     * @param id Name of the entity being expanded
+     * @param id Name of the entity being expanded 
      * @param allowExt Whether external entities can be expanded or not; if
      *   not, and the entity to expand would be external one, an exception
      *   will be thrown
      */
     protected EntityDecl expandEntity(String id, boolean allowExt,
                                       Object extraArg)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         mCurrName = id;
 
@@ -1621,7 +1608,7 @@
 
         if (ed == null) {
             /* 30-Sep-2005, TSa: As per [WSTX-5], let's only throw exception
-             *   if we have to resolve it (otherwise it's just best-effort,
+             *   if we have to resolve it (otherwise it's just best-effort, 
              *   and null is ok)
              */
             /* 02-Oct-2005, TSa: Plus, [WSTX-4] adds "undeclared entity
@@ -1632,15 +1619,16 @@
             }
             return null;
         }
-
+        
         if (!mCfgTreatCharRefsAsEntities || this instanceof MinimalDTDReader) {
             expandEntity(ed, allowExt);
         }
-
+        
         return ed;
     }
 
     /**
+     *
      *<p>
      * note: defined as private for documentation, ie. it's just called
      * from within this class (not sub-classes), from one specific method
@@ -1650,7 +1638,7 @@
      * @param allowExt Whether external entities are allowed or not.
      */
     private void expandEntity(EntityDecl ed, boolean allowExt)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         String id = ed.getName();
 
@@ -1677,10 +1665,10 @@
             }
             if (!mConfig.willSupportExternalEntities()) {
                 throwParseError("Encountered a reference to external entity \"{0}\", but stream reader has feature \"{1}\" disabled",
-                        id, XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES);
+                                id, XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES);
             }
         }
-        verifyLimit("Maximum entity expansion count", mConfig.getMaxEntityCount(), ++mEntityExpansionCount);
+
         // First, let's give current context chance to save its stuff
         WstxInputSource oldInput = mInput;
         oldInput.saveContext(this);
@@ -1706,7 +1694,7 @@
      * note: only called from the local expandEntity() method
      */
     private EntityDecl expandUnresolvedEntity(String id)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         XMLResolver resolver = mConfig.getUndeclaredEntityResolver();
         if (resolver != null) {
@@ -1730,7 +1718,7 @@
             WstxInputSource newInput;
             try {
                 newInput = DefaultInputResolver.resolveEntityUsing
-                        (oldInput, id, null, null, resolver, mConfig, xmlVersion);
+                    (oldInput, id, null, null, resolver, mConfig, xmlVersion);
                 if (mCfgTreatCharRefsAsEntities) {
                     return new IntEntity(WstxInputLocation.getEmptyLocation(), newInput.getEntityId(),
                             newInput.getSource(), new char[]{}, WstxInputLocation.getEmptyLocation());
@@ -1749,9 +1737,9 @@
     }
 
     /*
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
     // Abstract methods for sub-classes to implement
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
      */
 
     /**
@@ -1763,7 +1751,7 @@
      *    reader.
      */
     protected abstract EntityDecl findEntity(String id, Object arg)
-            throws XMLStreamException;
+        throws XMLStreamException;
 
     /**
      * This method gets called if a declaration for an entity was not
@@ -1771,15 +1759,15 @@
      * always enabled for dtd reader).
      */
     protected abstract void handleUndeclaredEntity(String id)
-            throws XMLStreamException;
+        throws XMLStreamException;
 
     protected abstract void handleIncompleteEntityProblem(WstxInputSource closing)
-            throws XMLStreamException;
+        throws XMLStreamException;
 
     /*
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
     // Basic tokenization
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
      */
 
     /**
@@ -1787,7 +1775,7 @@
      * although bit lenier for more efficient handling); either uri prefix,
      * or local name.
      *<p>
-     * Much of complexity in this method has to do with the intention to
+     * Much of complexity in this method has to do with the intention to 
      * try to avoid any character copies. In this optimal case algorithm
      * would be fairly simple. However, this only works if all data is
      * already in input buffer... if not, copy has to be made halfway
@@ -1803,7 +1791,7 @@
      *    EOF or non-name-start char encountered)
      */
     protected String parseLocalName(char c)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         /* Has to start with letter, or '_' (etc); we won't allow ':' as that
          * is taken as namespace separator; no use trying to optimize
@@ -1817,7 +1805,7 @@
         }
 
         int ptr = mInputPtr;
-        int hash = c;
+        int hash = (int) c;
         final int inputLen = mInputEnd;
         int startPtr = ptr-1; // already read previous char
         final char[] inputBuf = mInputBuffer;
@@ -1842,7 +1830,7 @@
             if (!isNameChar(c)) {
                 break;
             }
-            hash = (hash * 31) + c;
+            hash = (hash * 31) + (int) c;
             ++ptr;
         }
         mInputPtr = ptr;
@@ -1858,7 +1846,7 @@
      * called very often.
      */
     protected String parseLocalName2(int start, int hash)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         int ptr = mInputEnd - start;
         // Let's assume fairly short names
@@ -1889,7 +1877,7 @@
                 outLen = outBuf.length;
             }
             outBuf[ptr++] = c;
-            hash = (hash * 31) + c;
+            hash = (hash * 31) + (int) c;
         }
         // Still need to canonicalize the name:
         return mSymbols.findSymbol(outBuf, 0, ptr, hash);
@@ -1908,12 +1896,12 @@
      *<p>
      * Note that returned String will be canonicalized, similar to
      * {@link #parseLocalName}, but without separating prefix/local name.
-     *
+      *
      * @return Canonicalized name String (which may have length 0, if
      *    EOF or non-name-start char encountered)
      */
     protected String parseFullName()
-            throws XMLStreamException
+        throws XMLStreamException
     {
         if (mInputPtr >= mInputEnd) {
             loadMoreFromCurrent();
@@ -1922,7 +1910,7 @@
     }
 
     protected String parseFullName(char c)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         // First char has special handling:
         if (!isNameStartChar(c)) {
@@ -1940,7 +1928,7 @@
         }
 
         int ptr = mInputPtr;
-        int hash = c;
+        int hash = (int) c;
         int inputLen = mInputEnd;
         int startPtr = ptr-1; // to account for the first char
 
@@ -1970,16 +1958,15 @@
                     break;
                 }
             }
-            hash = (hash * 31) + c;
+            hash = (hash * 31) + (int) c;
             ++ptr;
         }
         mInputPtr = ptr;
         return mSymbols.findSymbol(mInputBuffer, startPtr, ptr - startPtr, hash);
     }
 
-    @SuppressWarnings("cast")
     protected String parseFullName2(int start, int hash)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         int ptr = mInputEnd - start;
         // Let's assume fairly short names
@@ -2033,9 +2020,9 @@
      * messages.
      */
     protected String parseFNameForError()
-            throws XMLStreamException
+        throws XMLStreamException
     {
-        StringBuilder sb = new StringBuilder(100);
+        StringBuffer sb = new StringBuffer(100);
         while (true) {
             char c;
 
@@ -2058,7 +2045,7 @@
     }
 
     protected final String parseEntityName(char c)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         String id = parseFullName(c);
         // Needs to be followed by a semi-colon, too.. from same input source:
@@ -2073,7 +2060,7 @@
         }
         return id;
     }
-
+    
     /**
      * Note: does not check for number of colons, amongst other things.
      * Main idea is to skip through what superficially seems like a valid
@@ -2084,7 +2071,7 @@
      * @return Length of skipped name.
      */
     protected int skipFullName(char c)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         if (!isNameStartChar(c)) {
             --mInputPtr;
@@ -2097,7 +2084,7 @@
         int count = 1;
         while (true) {
             c = (mInputPtr < mInputEnd) ?
-                    mInputBuffer[mInputPtr++] : getNextChar(SUFFIX_EOF_EXP_NAME);
+                mInputBuffer[mInputPtr++] : getNextChar(SUFFIX_EOF_EXP_NAME);
             if (c != ':' && !isNameChar(c)) {
                 break;
             }
@@ -2120,14 +2107,14 @@
      */
     protected final String parseSystemId(char quoteChar, boolean convertLFs,
                                          String errorMsg)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         char[] buf = getNameBuffer(-1);
         int ptr = 0;
 
         while (true) {
             char c = (mInputPtr < mInputEnd) ?
-                    mInputBuffer[mInputPtr++] : getNextChar(errorMsg);
+                mInputBuffer[mInputPtr++] : getNextChar(errorMsg);
             if (c == quoteChar) {
                 break;
             }
@@ -2180,7 +2167,7 @@
      * likely to be a bottleneck for parsing.
      */
     protected final String parsePublicId(char quoteChar, String errorMsg)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         char[] buf = getNameBuffer(-1);
         int ptr = 0;
@@ -2188,7 +2175,7 @@
 
         while (true) {
             char c = (mInputPtr < mInputEnd) ?
-                    mInputBuffer[mInputPtr++] : getNextChar(errorMsg);
+                mInputBuffer[mInputPtr++] : getNextChar(errorMsg);
             if (c == quoteChar) {
                 break;
             }
@@ -2208,11 +2195,11 @@
             } else {
                 // Verify it's a legal pubid char (see XML spec, #13, from 2.3)
                 if ((c >= VALID_PUBID_CHAR_COUNT)
-                        || sPubidValidity[c] != PUBID_CHAR_VALID_B) {
+                    || sPubidValidity[c] != PUBID_CHAR_VALID_B) {
                     throwUnexpectedChar(c, " in public identifier");
                 }
             }
-
+        
             // Other than that, let's just append it:
             if (ptr >= buf.length) {
                 buf = expandBy50Pct(buf);
@@ -2238,13 +2225,13 @@
             }
             buf[ptr++] = c;
         }
-
+      
         return (ptr == 0) ? "" : new String(buf, 0, ptr);
     }
 
     protected final void parseUntil(TextBuffer tb, char endChar, boolean convertLFs,
                                     String errorMsg)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         // Let's first ensure we have some data in there...
         if (mInputPtr >= mInputEnd) {
@@ -2311,29 +2298,29 @@
     }
 
     /*
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
     // Internal methods
-    ///////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////
      */
 
     private int resolveCharEnt(StringBuffer originalCharacters)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         int value = 0;
         char c = getNextChar(SUFFIX_IN_ENTITY_REF);
-
+        
         if (originalCharacters != null) {
             originalCharacters.append(c);
         }
-
+        
         if (c == 'x') { // hex
             while (true) {
                 c = (mInputPtr < mInputEnd) ? mInputBuffer[mInputPtr++]
-                        : getNextCharFromCurrent(SUFFIX_IN_ENTITY_REF);
+                    : getNextCharFromCurrent(SUFFIX_IN_ENTITY_REF);
                 if (c == ';') {
                     break;
                 }
-
+                
                 if (originalCharacters != null) {
                     originalCharacters.append(c);
                 }
@@ -2364,8 +2351,8 @@
                     throwUnexpectedChar(c, "; expected a decimal number.");
                 }
                 c = (mInputPtr < mInputEnd) ? mInputBuffer[mInputPtr++]
-                        : getNextCharFromCurrent(SUFFIX_IN_ENTITY_REF);
-
+                    : getNextCharFromCurrent(SUFFIX_IN_ENTITY_REF);
+                
                 if (originalCharacters != null && c != ';') {
                     originalCharacters.append(c);
                 }
@@ -2380,7 +2367,7 @@
      * XML content character.
      */
     private final void validateChar(int value)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         /* 24-Jan-2006, TSa: Ok, "high" Unicode chars are problematic,
          *   need to be reported by a surrogate pair..
@@ -2405,7 +2392,7 @@
             // XML 1.1 allows most other chars; 1.0 does not:
             if (!mXml10AllowAllEscapedChars) {
                 if (!mXml11 &&
-                        (value != 0x9 && value != 0xA && value != 0xD)) {
+                    (value != 0x9 && value != 0xA && value != 0xD)) {
                     reportIllegalChar(value);
                 }
             }
@@ -2415,7 +2402,7 @@
     protected final char[] getNameBuffer(int minSize)
     {
         char[] buf = mNameBuffer;
-
+        
         if (buf == null) {
             mNameBuffer = buf = new char[(minSize > 48) ? (minSize+16) : 64];
         } else if (minSize >= buf.length) { // let's allow one char extra...
@@ -2425,7 +2412,7 @@
         }
         return buf;
     }
-
+    
     protected final char[] expandBy50Pct(char[] buf)
     {
         int len = buf.length;
@@ -2440,40 +2427,26 @@
      * is one, and reader is namespace aware.
      */
     private void throwNsColonException(String name)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         throwParseError("Illegal name \"{0}\" (PI target, entity/notation name): can not contain a colon (XML Namespaces 1.0#6)", name, null);
     }
 
     private void throwRecursionError(String entityName)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         throwParseError("Illegal entity expansion: entity \"{0}\" expands itself recursively.", entityName, null);
     }
 
     private void reportUnicodeOverflow()
-            throws XMLStreamException
+        throws XMLStreamException
     {
         throwParseError("Illegal character entity: value higher than max allowed (0x{0})", Integer.toHexString(MAX_UNICODE_CHAR), null);
     }
 
     private void reportIllegalChar(int value)
-            throws XMLStreamException
+        throws XMLStreamException
     {
         throwParseError("Illegal character entity: expansion character (code 0x{0}", Integer.toHexString(value), null);
     }
-
-    protected void verifyLimit(String type, long maxValue, long currentValue)
-            throws XMLStreamException
-    {
-        if (currentValue > maxValue) {
-            throw constructLimitViolation(type, maxValue);
-        }
-    }
-
-    protected XMLStreamException constructLimitViolation(String type, long limit)
-            throws XMLStreamException
-    {
-        return new XMLStreamException(type+" limit ("+limit+") exceeded");
-    }
 }
