spotbugs fixes

git-svn-id: https://svn.apache.org/repos/asf/xmlbeans/trunk@1881876 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/xmlbeans/impl/util/FilerImpl.java b/src/main/java/org/apache/xmlbeans/impl/util/FilerImpl.java
index 14e9b3b..de5862f 100755
--- a/src/main/java/org/apache/xmlbeans/impl/util/FilerImpl.java
+++ b/src/main/java/org/apache/xmlbeans/impl/util/FilerImpl.java
@@ -158,14 +158,12 @@
             List<String> diffs = new ArrayList<>();
 
             try (StringReader sReader = new StringReader(str);
-                 FileReader fReader = new FileReader(_file)) {
-                Diff.readersAsText(sReader, "<generated>",
-                    fReader, _file.getName(), diffs);
+                 Reader fReader = Files.newBufferedReader(_file.toPath(), StandardCharsets.ISO_8859_1)) {
+                Diff.readersAsText(sReader, "<generated>", fReader, _file.getName(), diffs);
             }
 
             if (diffs.size() > 0) {
-                // Diffs encountered, replace the file on disk with text from
-                // the buffer
+                // Diffs encountered, replace the file on disk with text from the buffer
                 try (Writer fw = writerForFile(_file)) {
                     fw.write(str);
                 }
diff --git a/src/main/java/org/apache/xmlbeans/impl/validator/Validator.java b/src/main/java/org/apache/xmlbeans/impl/validator/Validator.java
index 724a64f..f39bb29 100644
--- a/src/main/java/org/apache/xmlbeans/impl/validator/Validator.java
+++ b/src/main/java/org/apache/xmlbeans/impl/validator/Validator.java
@@ -26,6 +26,7 @@
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.util.*;
+import java.util.stream.Collectors;
 
 public final class Validator
     implements ValidatorListener {
@@ -56,15 +57,15 @@
             // TODO (dutta) Addtional Attributes for validation error have limited information
             //at this time but will be a part of the second round of refactoring
 
-            Validator.this.emitError(_event, message, null, null, null,
-                XmlValidationError.ATTRIBUTE_TYPE_INVALID, null);
+            Validator.this.emitError(_event, message, null, null,
+                XmlValidationError.ATTRIBUTE_TYPE_INVALID);
         }
 
         public void invalid(String code, Object[] args) {
             // TODO (dutta) Addtional Attributes for validation error have limited information
             //at this time but will be a part of the second round of refactoring
 
-            Validator.this.emitError(_event, code, args, null, null, null,
+            Validator.this.emitError(_event, code, args, null, null,
                 XmlValidationError.ATTRIBUTE_TYPE_INVALID, null);
         }
 
@@ -77,23 +78,23 @@
 
     // KHK: remove this
     private void emitError(Event event, String message, QName offendingQName,
-                           SchemaType expectedSchemaType, List expectedQNames,
-                           int errorType, SchemaType badSchemaType) {
+                           SchemaType expectedSchemaType,
+                           int errorType) {
         emitError(event, message, null, null, XmlError.SEVERITY_ERROR, null, offendingQName, expectedSchemaType,
-            expectedQNames, errorType, badSchemaType);
+            null, errorType, null);
     }
 
     private void emitError(Event event, String code, Object[] args, QName offendingQName,
-                           SchemaType expectedSchemaType, List expectedQNames,
+                           SchemaType expectedSchemaType,
                            int errorType, SchemaType badSchemaType) {
         emitError(event, null, code, args, XmlError.SEVERITY_ERROR, null, offendingQName, expectedSchemaType,
-            expectedQNames, errorType, badSchemaType);
+            null, errorType, badSchemaType);
     }
 
     // KHK: remove 'message' parameter
     private void emitError(Event event, String message, String code, Object[] args, int severity,
                            QName fieldName, QName offendingQName,
-                           SchemaType expectedSchemaType, List expectedQNames,
+                           SchemaType expectedSchemaType, List<QName> expectedQNames,
                            int errorType, SchemaType badSchemaType) {
         _errorState++;
 
@@ -124,39 +125,17 @@
     }
 
     private void emitFieldError(Event event, String code, Object[] args, QName offendingQName,
-                                SchemaType expectedSchemaType, List expectedQNames,
-                                int errorType, SchemaType badSchemaType) {
-        emitFieldError(event, null, code, args, XmlError.SEVERITY_ERROR, offendingQName,
-            expectedSchemaType, expectedQNames, errorType, badSchemaType);
-    }
-
-    private void emitFieldError(Event event, String message, String code, Object[] args, int severity, QName offendingQName,
-                                SchemaType expectedSchemaType, List expectedQNames,
+                                SchemaType expectedSchemaType, List<QName> expectedQNames,
                                 int errorType, SchemaType badSchemaType) {
         QName fieldName = null;
         if (_stateStack != null && _stateStack._field != null) {
             fieldName = _stateStack._field.getName();
         }
 
-        Validator.this.emitError(event, message, code, args, severity, fieldName, offendingQName, expectedSchemaType,
+        Validator.this.emitError(event, null, code, args, XmlError.SEVERITY_ERROR, fieldName, offendingQName, expectedSchemaType,
             expectedQNames, errorType, badSchemaType);
     }
 
-//    // For XmlEventListener.error
-//
-//    public void error ( XmlError error )
-//    {
-//        _errorState++;
-//
-//        if (_suspendErrors == 0)
-//        {
-//            _invalid = true;
-//
-//            if (_errorListener != null)
-//                _errorListener.add( error );
-//        }
-//    }
-
     public void nextEvent(int kind, Event event) {
         resetValues();
 
@@ -199,8 +178,8 @@
         _wildcardElement = null;
         State state = topState();
 
-        SchemaType elementType = null;
-        SchemaField elementField = null;
+        SchemaType elementType;
+        SchemaField elementField;
 
         if (state == null) {
             elementType = _rootType;
@@ -222,7 +201,7 @@
                 return;
             }
 
-            if (!state._isNil && state._field != null && state._field.isFixed()) {
+            if (state._field != null && state._field.isFixed()) {
                 emitFieldError(event, XmlErrorCodes.ELEM_LOCALLY_VALID$FIXED_WITH_CONTENT,
                     new Object[]{QNameHelper.pretty(state._field.getName())},
                     state._field.getName(), state._type, null,
@@ -305,10 +284,8 @@
 
                     assert newField != null;
 
-                    if (newField != null) {
-                        elementField = newField;
-                        _localElement = newField;
-                    }
+                    elementField = newField;
+                    _localElement = newField;
                 } else {
                     elementField = (SchemaField) currentParticle;
                 }
@@ -362,7 +339,7 @@
                 // not sure how to extract this one
                 emitFieldError(event, XmlErrorCodes.ELEM_LOCALLY_VALID$XSI_TYPE_INVALID_QNAME,
                     new Object[]{value}, event.getName(), xsiType, null,
-                    XmlValidationError.ELEMENT_TYPE_INVALID, state._type);
+                    XmlValidationError.ELEMENT_TYPE_INVALID, (state == null ? null : state._type));
 
                 _eatContent = 1;
 
@@ -453,17 +430,17 @@
                 //todo (dutta) need to find a way to get the right type
                 emitError(event, XmlErrorCodes.ELEM_LOCALLY_VALID$ABSTRACT,
                     new Object[]{QNameHelper.pretty(sle.getName())},
-                    sle.getName(), null, null, XmlValidationError.ELEMENT_TYPE_INVALID, null);
+                    sle.getName(), null, XmlValidationError.ELEMENT_TYPE_INVALID, null);
 
                 _eatContent = 1;
                 return;
             }
         }
 
-        if (elementType != null && elementType.isAbstract()) {
+        if (elementType.isAbstract()) {
             emitError(event, XmlErrorCodes.ELEM_LOCALLY_VALID$ABSTRACT,
                 new Object[]{elementType},
-                event.getName(), elementType, null, XmlValidationError.ELEMENT_TYPE_INVALID, (state == null ? null : state._type));
+                event.getName(), elementType, XmlValidationError.ELEMENT_TYPE_INVALID, (state == null ? null : state._type));
 
             _eatContent = 1;
 
@@ -493,7 +470,7 @@
 
         if (isNil && elementField != null && elementField.isFixed()) {
             emitFieldError(event, XmlErrorCodes.ELEM_LOCALLY_VALID$NIL_WITH_FIXED, null,
-                elementField == null ? null : elementField.getName(), elementType, null,
+                elementField.getName(), elementType, null,
                 XmlValidationError.ELEMENT_TYPE_INVALID, (state == null ? null : state._type));
         }
 
@@ -516,7 +493,7 @@
         State state = topState();
 
         if (state._attrs == null) {
-            state._attrs = new HashSet();
+            state._attrs = new HashSet<>();
         }
 
         if (state._attrs.contains(attrName)) {
@@ -622,9 +599,7 @@
         if (state._attrModel != null) {
             SchemaLocalAttribute[] attrs = state._attrModel.getAttributes();
 
-            for (int i = 0; i < attrs.length; i++) {
-                SchemaLocalAttribute sla = attrs[i];
-
+            for (SchemaLocalAttribute sla : attrs) {
                 if (state._attrs == null ||
                     !state._attrs.contains(sla.getName())) {
                     if (sla.getUse() == SchemaLocalAttribute.REQUIRED) {
@@ -744,13 +719,13 @@
                     XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$ELEMENT_ONLY_WITH_TEXT);
 
                 emitError(event, errorCode, new Object[]{QNameHelper.pretty(e.getName())},
-                    e.getName(), field.getType(), null,
+                    e.getName(), field.getType(),
                     XmlValidationError.ELEMENT_TYPE_INVALID, null);
             } else {
                 // KHK: cvc-complex-type.2.1 or .2.3
                 // todo (dutta) offendingQName = not sure how to get this(event.getName()??);
                 emitError(event, "Can't have mixed content", event.getName(),
-                    state._type, null, XmlValidationError.ELEMENT_TYPE_INVALID, null);
+                    state._type, XmlValidationError.ELEMENT_TYPE_INVALID);
             }
         }
 
@@ -760,14 +735,12 @@
     }
 
     private void findDetailedErrorBegin(Event event, State state, QName qName) {
-        ArrayList expectedNames = new ArrayList();
-        ArrayList optionalNames = new ArrayList();
+        ArrayList<QName> expectedNames = new ArrayList<>();
+        ArrayList<QName> optionalNames = new ArrayList<>();
 
         SchemaProperty[] eltProperties = state._type.getElementProperties();
-        for (int ii = 0; ii < eltProperties.length; ii++) {
+        for (SchemaProperty sProp : eltProperties) {
             //Get the element from the schema
-            SchemaProperty sProp = eltProperties[ii];
-
             // test if the element is valid
             if (state.test(sProp.getName())) {
                 if (0 == BigInteger.ZERO.compareTo(sProp.getMinOccurs())) {
@@ -778,20 +751,12 @@
             }
         }
 
-        List names = (expectedNames.size() > 0 ? expectedNames : optionalNames);
+        List<QName> names = (expectedNames.size() > 0 ? expectedNames : optionalNames);
 
         if (names.size() > 0) {
-            StringBuilder buf = new StringBuilder();
-            for (Iterator iter = names.iterator(); iter.hasNext(); ) {
-                QName qname = (QName) iter.next();
-                buf.append(QNameHelper.pretty(qname));
-                if (iter.hasNext()) {
-                    buf.append(" ");
-                }
-            }
-
+            String buf = names.stream().map(QNameHelper::pretty).collect(Collectors.joining(" "));
             emitFieldError(event, XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$EXPECTED_DIFFERENT_ELEMENT,
-                new Object[]{new Integer(names.size()), buf.toString(), QNameHelper.pretty(qName)},
+                new Object[]{names.size(), buf, QNameHelper.pretty(qName)},
                 qName, null, names, XmlValidationError.INCORRECT_ELEMENT, state._type);
         } else {
             emitFieldError(event, XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$ELEMENT_NOT_ALLOWED,
@@ -803,13 +768,11 @@
     private void findDetailedErrorEnd(Event event, State state) {
         SchemaProperty[] eltProperties = state._type.getElementProperties();
 
-        ArrayList expectedNames = new ArrayList();
-        ArrayList optionalNames = new ArrayList();
+        ArrayList<QName> expectedNames = new ArrayList<>();
+        ArrayList<QName> optionalNames = new ArrayList<>();
 
-        for (int ii = 0; ii < eltProperties.length; ii++) {
+        for (SchemaProperty sProp : eltProperties) {
             //Get the element from the schema
-            SchemaProperty sProp = eltProperties[ii];
-
             // test if the element is valid
             if (state.test(sProp.getName())) {
                 if (0 == BigInteger.ZERO.compareTo(sProp.getMinOccurs())) {
@@ -820,20 +783,13 @@
             }
         }
 
-        List names = (expectedNames.size() > 0 ? expectedNames : optionalNames);
+        List<QName> names = (expectedNames.size() > 0 ? expectedNames : optionalNames);
 
         if (names.size() > 0) {
-            StringBuilder buf = new StringBuilder();
-            for (Iterator iter = names.iterator(); iter.hasNext(); ) {
-                QName qname = (QName) iter.next();
-                buf.append(QNameHelper.pretty(qname));
-                if (iter.hasNext()) {
-                    buf.append(" ");
-                }
-            }
+            String buf = names.stream().map(QNameHelper::pretty).collect(Collectors.joining(" "));
 
             emitFieldError(event, XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$MISSING_ELEMENT,
-                new Object[]{new Integer(names.size()), buf.toString()},
+                new Object[]{names.size(), buf},
                 null, null, names, XmlValidationError.INCORRECT_ELEMENT, state._type);
         } else {
             emitFieldError(event, XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$EXPECTED_ELEMENT,
@@ -842,7 +798,7 @@
     }
 
 
-    private final class State {
+    private static final class State {
         boolean visit(QName name) {
             return _canHaveElements && _visitor.visit(name);
         }
@@ -876,7 +832,7 @@
 
         SchemaAttributeModel _attrModel;
 
-        HashSet _attrs;
+        HashSet<QName> _attrs;
 
         State _next;
     }
@@ -952,7 +908,7 @@
         _stateStack = state;
     }
 
-    private LinkedList _visitorPool = new LinkedList();
+    private final LinkedList<TypeStoreVisitor> _visitorPool = new LinkedList<>();
 
     private void poolVisitor(SchemaTypeVisitorImpl visitor) {
         _visitorPool.add(visitor);
@@ -999,7 +955,7 @@
 
         if (type.isNoType()) {
             emitError(event, (field.isAttribute() ? XmlErrorCodes.ATTR_LOCALLY_VALID$NO_TYPE : XmlErrorCodes.ELEM_LOCALLY_VALID$NO_TYPE),
-                null, field.getName(), type, null, XmlValidationError.ELEMENT_TYPE_INVALID, null);
+                null, field.getName(), type, XmlValidationError.ELEMENT_TYPE_INVALID, null);
 
             return null;
         }
@@ -1064,7 +1020,7 @@
                     // KHK: check for is cvc-complex-type.3.1 or cvc-au
                     emitError(event, XmlErrorCodes.ATTR_LOCALLY_VALID$FIXED,
                         new Object[]{value, fixedValue, QNameHelper.pretty(event.getName())},
-                        null, field.getType(), null, XmlValidationError.ELEMENT_TYPE_INVALID, null);
+                        null, field.getType(), XmlValidationError.ELEMENT_TYPE_INVALID, null);
                 } else {
                     String errorCode = null;
 
@@ -1077,9 +1033,8 @@
                         assert false : "Element with fixed may not be EMPTY or ELEMENT_ONLY";
                     }
 
-                    emitError(event, errorCode,
-                        new Object[]{value, fixedValue},
-                        field.getName(), field.getType(), null, XmlValidationError.ELEMENT_TYPE_INVALID, null);
+                    emitError(event, errorCode, new Object[]{value, fixedValue},
+                        field.getName(), field.getType(), XmlValidationError.ELEMENT_TYPE_INVALID, null);
                 }
 
                 return null;
@@ -1287,7 +1242,7 @@
         if (!type.matchPatternFacet(value)) {
             emitError(event, XmlErrorCodes.DATATYPE_VALID$PATTERN_VALID,
                 new Object[]{"list", value, QNameHelper.readable(type)},
-                null, type, null, XmlValidationError.LIST_INVALID, null);
+                null, type, XmlValidationError.LIST_INVALID, null);
         }
 
         String[] items = XmlListImpl.split_list(value);
@@ -1299,8 +1254,8 @@
             if ((i = ((SimpleValue) o).getIntValue()) != items.length) {
                 //offending Qname not valid
                 emitError(event, XmlErrorCodes.DATATYPE_LENGTH_VALID$LIST_LENGTH,
-                    new Object[]{value, new Integer(items.length), new Integer(i), QNameHelper.readable(type)},
-                    null, type, null, XmlValidationError.LIST_INVALID, null);
+                    new Object[]{value, items.length, i, QNameHelper.readable(type)},
+                    null, type, XmlValidationError.LIST_INVALID, null);
             }
         }
 
@@ -1308,8 +1263,8 @@
             if ((i = ((SimpleValue) o).getIntValue()) > items.length) {
                 //offending Qname not valid
                 emitError(event, XmlErrorCodes.DATATYPE_LENGTH_VALID$LIST_LENGTH,
-                    new Object[]{value, new Integer(items.length), new Integer(i), QNameHelper.readable(type)},
-                    null, type, null, XmlValidationError.LIST_INVALID, null);
+                    new Object[]{value, items.length, i, QNameHelper.readable(type)},
+                    null, type, XmlValidationError.LIST_INVALID, null);
             }
         }
 
@@ -1317,14 +1272,14 @@
             if ((i = ((SimpleValue) o).getIntValue()) < items.length) {
                 //offending Qname not valid
                 emitError(event, XmlErrorCodes.DATATYPE_LENGTH_VALID$LIST_LENGTH,
-                    new Object[]{value, new Integer(items.length), new Integer(i), QNameHelper.readable(type)},
-                    null, type, null, XmlValidationError.LIST_INVALID, null);
+                    new Object[]{value, items.length, i, QNameHelper.readable(type)},
+                    null, type, XmlValidationError.LIST_INVALID, null);
             }
         }
 
         SchemaType itemType = type.getListItemType();
-        _listValue = new ArrayList();
-        _listTypes = new ArrayList();
+        _listValue = new ArrayList<>();
+        _listTypes = new ArrayList<>();
 
         for (i = 0; i < items.length; i++) {
             validateSimpleType(
@@ -1348,7 +1303,7 @@
                     //offending Qname not valid ??
                     emitError(event, XmlErrorCodes.DATATYPE_ENUM_VALID,
                         new Object[]{"list", value, QNameHelper.readable(type)},
-                        null, type, null, XmlValidationError.LIST_INVALID, null);
+                        null, type, XmlValidationError.LIST_INVALID, null);
                 } finally {
                     NamespaceContext.pop();
                 }
@@ -1365,7 +1320,7 @@
             //offending Qname not valid ??
             emitError(event, XmlErrorCodes.DATATYPE_VALID$PATTERN_VALID,
                 new Object[]{"union", value, QNameHelper.readable(type)},
-                null, type, null, XmlValidationError.UNION_INVALID, null);
+                null, type, XmlValidationError.UNION_INVALID, null);
         }
 
         int currentWsr = SchemaType.WS_PRESERVE;
@@ -1410,7 +1365,7 @@
             //offending Qname not valid ??
             emitError(event, XmlErrorCodes.DATATYPE_VALID$UNION,
                 new Object[]{value, QNameHelper.readable(type)},
-                null, type, null, XmlValidationError.UNION_INVALID, null);
+                null, type, XmlValidationError.UNION_INVALID, null);
         } else {
             XmlObject[] unionEnumvals = type.getEnumerationValues();
 
@@ -1432,7 +1387,7 @@
                         //offending Qname not valid ??
                         emitError(event, XmlErrorCodes.DATATYPE_ENUM_VALID,
                             new Object[]{"union", value, QNameHelper.readable(type)},
-                            null, type, null, XmlValidationError.UNION_INVALID, null);
+                            null, type, XmlValidationError.UNION_INVALID, null);
                     }
                 } catch (XmlValueOutOfRangeException e) {
                     // actually, the current union code always ends up here when invalid
@@ -1440,7 +1395,7 @@
                     //offending Qname not valid ??
                     emitError(event, XmlErrorCodes.DATATYPE_ENUM_VALID,
                         new Object[]{"union", value, QNameHelper.readable(type)},
-                        null, type, null, XmlValidationError.UNION_INVALID, null);
+                        null, type, XmlValidationError.UNION_INVALID, null);
                 } finally {
                     NamespaceContext.pop();
                 }
@@ -1469,7 +1424,8 @@
         }
 
         switch (type.getPrimitiveType().getBuiltinTypeCode()) {
-            case SchemaType.BTC_ANY_SIMPLE: {
+            case SchemaType.BTC_ANY_SIMPLE:
+            case SchemaType.BTC_ANY_URI: {
                 _listValue.add(_stringValue);
                 break;
             }
@@ -1489,24 +1445,21 @@
                 break;
             }
             case SchemaType.BTC_FLOAT: {
-                _listValue.add(new Float(_floatValue));
+                _listValue.add(_floatValue);
                 _floatValue = 0;
                 break;
             }
             case SchemaType.BTC_DOUBLE: {
-                _listValue.add(new Double(_doubleValue));
+                _listValue.add(_doubleValue);
                 _doubleValue = 0;
                 break;
             }
-            case SchemaType.BTC_QNAME: {
+            case SchemaType.BTC_QNAME:
+            case SchemaType.BTC_NOTATION: {
                 _listValue.add(_qnameValue);
                 _qnameValue = null;
                 break;
             }
-            case SchemaType.BTC_ANY_URI: {
-                _listTypes.add(_stringValue);
-                break;
-            }
             case SchemaType.BTC_DATE_TIME:
             case SchemaType.BTC_TIME:
             case SchemaType.BTC_DATE:
@@ -1524,21 +1477,12 @@
                 _gdurationValue = null;
                 break;
             }
-            case SchemaType.BTC_BASE_64_BINARY: {
-                _listValue.add(_byteArrayValue);
-                _byteArrayValue = null;
-                break;
-            }
+            case SchemaType.BTC_BASE_64_BINARY:
             case SchemaType.BTC_HEX_BINARY: {
                 _listValue.add(_byteArrayValue);
                 _byteArrayValue = null;
                 break;
             }
-            case SchemaType.BTC_NOTATION: {
-                _listValue.add(_qnameValue);
-                _qnameValue = null;
-                break;
-            }
 
             default:
                 throw new RuntimeException("Unexpected primitive type code");
@@ -1550,17 +1494,17 @@
     //
 
     private boolean _invalid;
-    private SchemaType _rootType;
-    private SchemaField _rootField;
-    private SchemaTypeLoader _globalTypes;
+    private final SchemaType _rootType;
+    private final SchemaField _rootField;
+    private final SchemaTypeLoader _globalTypes;
     private State _stateStack;
     private int _errorState;
     private Collection<XmlError> _errorListener;
-    private boolean _treatLaxAsSkip;
-    private boolean _strict;
-    private ValidatorVC _vc;
+    private final boolean _treatLaxAsSkip;
+    private final boolean _strict;
+    private final ValidatorVC _vc;
     private int _suspendErrors;
-    private IdentityConstraint _constraintEngine;
+    private final IdentityConstraint _constraintEngine;
     private int _eatContent;
 
     private SchemaLocalElement _localElement;
@@ -1579,8 +1523,8 @@
     private GDate _gdateValue;
     private GDuration _gdurationValue;
     private byte[] _byteArrayValue;
-    private List _listValue;
-    private List _listTypes;
+    private List<Object> _listValue;
+    private List<SchemaType> _listTypes;
 
     private void resetValues() {
         _localAttribute = null;
@@ -1597,7 +1541,6 @@
         _listValue = null;
         _listTypes = null;
         _unionType = null;
-        _localAttribute = null;
     }
 
     /**
@@ -1700,11 +1643,11 @@
         return _byteArrayValue;
     }
 
-    public List getListValue() {
+    public List<Object> getListValue() {
         return _listValue;
     }
 
-    public List getListTypes() {
+    public List<SchemaType> getListTypes() {
         return _listTypes;
     }
 
diff --git a/src/main/java/org/apache/xmlbeans/soap/SOAPArrayType.java b/src/main/java/org/apache/xmlbeans/soap/SOAPArrayType.java
index db24214..48ecd2d 100644
--- a/src/main/java/org/apache/xmlbeans/soap/SOAPArrayType.java
+++ b/src/main/java/org/apache/xmlbeans/soap/SOAPArrayType.java
@@ -15,19 +15,19 @@
 
 package org.apache.xmlbeans.soap;
 
-import javax.xml.namespace.QName;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Iterator;
-
-import org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException;
-import org.apache.xmlbeans.impl.common.XmlWhitespace;
-import org.apache.xmlbeans.impl.common.QNameHelper;
 import org.apache.xmlbeans.impl.common.PrefixResolver;
+import org.apache.xmlbeans.impl.common.QNameHelper;
+import org.apache.xmlbeans.impl.common.XmlWhitespace;
+import org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException;
 
-public final class SOAPArrayType
-{
+import javax.xml.namespace.QName;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+public final class SOAPArrayType {
     // Example foo:bar[,][][,,][7,9]
     // -> _type = QName(foo:bar)
     // -> _ranks = {2,1,3}
@@ -39,45 +39,20 @@
     /**
      * True if the ranks for the passed SOAPArrayType
      * are equal to this one.
-     *
+     * <p>
      * Does NOT compare the _type fields.
      */
-    public boolean isSameRankAs(SOAPArrayType otherType)
-    {
-        if (_ranks.length != otherType._ranks.length)
-            return false;
-        for (int i = 0; i < _ranks.length; i++)
-        {
-            if (_ranks[i] != otherType._ranks[i])
-                return false;
-        }
-        if (_dimensions.length != otherType._dimensions.length)
-            return false;
-        return true;
+    public boolean isSameRankAs(SOAPArrayType otherType) {
+        return Arrays.equals(_ranks, otherType._ranks) &&
+               _dimensions.length == otherType._dimensions.length;
     }
 
-    /**
-     * Given SOAP 1.1-formatted index string, returns an array
-     * index.  For example, given "[4,3,5]", returns an int array
-     * containing 4, 3, and 5.
-     */
-    public static int[] parseSoap11Index(String inbraces)
-    {
-        inbraces = XmlWhitespace.collapse(inbraces, XmlWhitespace.WS_COLLAPSE);
-        if (!inbraces.startsWith("[") || !inbraces.endsWith("]"))
-            throw new IllegalArgumentException("Misformed SOAP 1.1 index: must be contained in braces []");
-        return internalParseCommaIntString(inbraces.substring(1, inbraces.length() - 1));
-    }
-
-    private static int[] internalParseCommaIntString(String csl)
-    {
-        List dimStrings = new ArrayList();
+    private static int[] internalParseCommaIntString(String csl) {
+        List<String> dimStrings = new ArrayList<>();
         int i = 0;
-        for (;;)
-        {
+        for (; ; ) {
             int j = csl.indexOf(',', i);
-            if (j < 0)
-            {
+            if (j < 0) {
                 dimStrings.add(csl.substring(i));
                 break;
             }
@@ -85,99 +60,78 @@
             i = j + 1;
         }
 
-        int[] result = new int[dimStrings.size()];
-        i = 0;
-        for (Iterator it = dimStrings.iterator(); it.hasNext(); i++)
-        {
-            String dimString = XmlWhitespace.collapse((String)it.next(), XmlWhitespace.WS_COLLAPSE);
-            if (dimString.equals("*") || dimString.equals(""))
-            {
-                result[i] = -1;
-            }
-            else
-            {
-                try
-                {
-                    result[i] = Integer.parseInt(dimString);
-                }
-                catch (Exception e)
-                {
-                    throw new XmlValueOutOfRangeException("Malformed integer in SOAP array index");
-                }
-            }
+        return dimStrings.stream().mapToInt(SOAPArrayType::collapseDimString).toArray();
+    }
+
+    private static int collapseDimString(String dimString2) {
+        String dimString = XmlWhitespace.collapse(dimString2, XmlWhitespace.WS_COLLAPSE);
+        try {
+            return ("*".equals(dimString) || dimString.isEmpty()) ? -1 : Integer.parseInt(dimString);
+        } catch (Exception e) {
+            throw new XmlValueOutOfRangeException("Malformed integer in SOAP array index");
         }
-        return result;
     }
 
     /**
      * Parses a SOAP 1.1 array type string.
-     *
+     * <p>
      * Since an array type string contains a QName, a prefix resolver
      * must be passed.
      */
-    public SOAPArrayType(String s, PrefixResolver m)
-    {
+    public SOAPArrayType(String s, PrefixResolver m) {
         int firstbrace = s.indexOf('[');
-        if (firstbrace < 0)
+        if (firstbrace < 0) {
             throw new XmlValueOutOfRangeException();
+        }
 
         // grab the QName
         String firstpart = XmlWhitespace.collapse(s.substring(0, firstbrace), XmlWhitespace.WS_COLLAPSE);
         int firstcolon = firstpart.indexOf(':');
         String prefix = "";
-        if (firstcolon >= 0)
+        if (firstcolon >= 0) {
             prefix = firstpart.substring(0, firstcolon);
+        }
 
         String uri = m.getNamespaceForPrefix(prefix);
-        if (uri == null)
+        if (uri == null) {
             throw new XmlValueOutOfRangeException();
+        }
 
         _type = QNameHelper.forLNS(firstpart.substring(firstcolon + 1), uri);
 
         initDimensions(s, firstbrace);
     }
 
-    private static int[] EMPTY_INT_ARRAY = new int[0];
+    private static final int[] EMPTY_INT_ARRAY = new int[0];
 
     /**
      * Parses SOAP 1.1(advanced) array type strings.
-     *
+     * <p>
      * Since in SOAP 1.1(advanced) the dimension specification is separated from the
      * QName for the underlying type, these are passed in separate
      * arguments.
      */
-    public SOAPArrayType(QName name, String dimensions)
-    {
+    public SOAPArrayType(QName name, String dimensions) {
         int firstbrace = dimensions.indexOf('[');
-        if (firstbrace < 0)
-        {
+        if (firstbrace < 0) {
             _type = name;
             _ranks = EMPTY_INT_ARRAY;
             dimensions = XmlWhitespace.collapse(dimensions, XmlWhitespace.WS_COLLAPSE);
             String[] dimStrings = dimensions.split(" ");
-            for (int i = 0; i < dimStrings.length; i++)
-            {
+            for (int i = 0; i < dimStrings.length; i++) {
                 String dimString = dimStrings[i];
-                if (dimString.equals("*"))
-                {
+                if (dimString.equals("*")) {
                     _dimensions[i] = -1;
                     // _hasIndeterminateDimensions = true;
-                }
-                else
-                {
-                    try
-                    {
+                } else {
+                    try {
                         _dimensions[i] = Integer.parseInt(dimStrings[i]);
-                    }
-                    catch (Exception e)
-                    {
+                    } catch (Exception e) {
                         throw new XmlValueOutOfRangeException();
                     }
                 }
             }
-        }
-        else
-        {
+        } else {
             _type = name;
             initDimensions(dimensions, firstbrace);
         }
@@ -186,14 +140,13 @@
     /**
      * Given a nested SOAPArrayType and a set of dimensions for the outermost
      * array, comes up with the right SOAPArrayType for the whole thing.
-     *
+     * <p>
      * E.g.,
      * Nested foo:bar[,][][,,][1,2]
      * Dimensions [6,7,8]
      * Result -> foo:bar[,][][,,][,][6,7,8]
      */
-    public SOAPArrayType(SOAPArrayType nested, int[] dimensions)
-    {
+    public SOAPArrayType(SOAPArrayType nested, int[] dimensions) {
         _type = nested._type;
 
         _ranks = new int[nested._ranks.length + 1];
@@ -207,42 +160,41 @@
     /**
      * Initialize dimensions based on SOAP11 parsed dimension substring
      */
-    private void initDimensions(String s, int firstbrace)
-    {
-        List braces = new ArrayList();
+    private void initDimensions(String s, int firstbrace) {
+        List<String> braces = new ArrayList<>();
         int lastbrace = -1;
-        for (int i = firstbrace; i >= 0; )
-        {
+        for (int i = firstbrace; i >= 0; ) {
             lastbrace = s.indexOf(']', i);
-            if (lastbrace < 0)
+            if (lastbrace < 0) {
                 throw new XmlValueOutOfRangeException();
+            }
             braces.add(s.substring(i + 1, lastbrace));
             i = s.indexOf('[', lastbrace);
         }
 
         String trailer = s.substring(lastbrace + 1);
-        if (!XmlWhitespace.isAllSpace(trailer))
+        if (!XmlWhitespace.isAllSpace(trailer)) {
             throw new XmlValueOutOfRangeException();
+        }
 
         // now fill in rank array
         _ranks = new int[braces.size() - 1];
-        for (int i = 0; i < _ranks.length; i++)
-        {
-            String commas = (String)braces.get(i);
+        for (int i = 0; i < _ranks.length; i++) {
+            String commas = braces.get(i);
             int commacount = 0;
-            for (int j = 0; j < commas.length(); j++)
-            {
+            for (int j = 0; j < commas.length(); j++) {
                 char ch = commas.charAt(j);
-                if (ch == ',')
+                if (ch == ',') {
                     commacount += 1;
-                else if (!XmlWhitespace.isSpace(ch))
+                } else if (!XmlWhitespace.isSpace(ch)) {
                     throw new XmlValueOutOfRangeException();
+                }
             }
             _ranks[i] = commacount + 1;
         }
 
         // finally fill in dimension array
-        _dimensions = internalParseCommaIntString((String)braces.get(braces.size() - 1));
+        _dimensions = internalParseCommaIntString(braces.get(braces.size() - 1));
 
         /*
         for (int i = 0; i < _dimensions.length; i++)
@@ -256,8 +208,7 @@
     /**
      * Returns the QName for the referenced type.
      */
-    public QName getQName()
-    {
+    public QName getQName() {
         return _type;
     }
 
@@ -268,8 +219,7 @@
      * arrays. For example foo:bar[,][,,][][5,6] will produce
      * a ranks result of 2, 3, 1.
      */
-    public int[] getRanks()
-    {
+    public int[] getRanks() {
         int[] result = new int[_ranks.length];
         System.arraycopy(_ranks, 0, result, 0, result.length);
         return result;
@@ -278,8 +228,7 @@
     /**
      * Returns the array of dimensions.
      */
-    public int[] getDimensions()
-    {
+    public int[] getDimensions() {
         int[] result = new int[_dimensions.length];
         System.arraycopy(_dimensions, 0, result, 0, result.length);
         return result;
@@ -289,16 +238,14 @@
      * True if this array contains nested arrays. Equivalent
      * to (getRanks().length > 0).
      */
-    public boolean containsNestedArrays()
-    {
+    public boolean containsNestedArrays() {
         return (_ranks.length > 0);
     }
 
     /**
      * Returns the dimensions as a string, e.g., [,][2,3,4]
      */
-    public String soap11DimensionString()
-    {
+    public String soap11DimensionString() {
         return soap11DimensionString(_dimensions);
     }
 
@@ -307,69 +254,51 @@
      * the default that is stored, outputs the soap arrayType
      * string.
      */
-    public String soap11DimensionString(int[] actualDimensions)
-    {
+    public String soap11DimensionString(int[] actualDimensions) {
         StringBuilder sb = new StringBuilder();
-        for (int i = 0; i < _ranks.length; i++)
-        {
+        for (int rank : _ranks) {
             sb.append('[');
-            for (int j = 1; j < _ranks[i]; j++)
+            for (int j = 1; j < rank; j++) {
                 sb.append(',');
+            }
             sb.append(']');
         }
 
-        sb.append('[');
-        for (int i = 0; i < actualDimensions.length; i++)
-        {
-            if (i > 0)
-                sb.append(',');
-            if (actualDimensions[i] >= 0)
-                sb.append(actualDimensions[i]);
-        }
-        sb.append(']');
+        sb.append(IntStream.of(actualDimensions).mapToObj(i -> i >= 0 ? Integer.toString(i) : "").collect(Collectors.joining(",", "[", "]")));
         return sb.toString();
     }
 
-    private SOAPArrayType()
-    {
+    private SOAPArrayType() {
     }
 
     /**
      * SOAP 1.2
      * Constructs a SOAPArrayType from soap-enc:itemType and
      * soap-enc:arraySize attributes
-     * @param itemType the item type QName
+     *
+     * @param itemType  the item type QName
      * @param arraySize a string with dimentions like: * 3 4
      * @return a SOAPArrayType to represent this
      */
-    public static SOAPArrayType newSoap12Array(QName itemType, String arraySize)
-    {
-        int [] ranks = EMPTY_INT_ARRAY;
+    public static SOAPArrayType newSoap12Array(QName itemType, String arraySize) {
         arraySize = XmlWhitespace.collapse(arraySize, XmlWhitespace.WS_COLLAPSE);
         String[] dimStrings = arraySize.split(" ");
         int[] dimensions = new int[dimStrings.length];
-        for (int i = 0; i < dimStrings.length; i++)
-        {
+        for (int i = 0; i < dimStrings.length; i++) {
             String dimString = dimStrings[i];
-            if (i==0 && dimString.equals("*"))
-            {
+            if (i == 0 && dimString.equals("*")) {
                 dimensions[i] = -1;
                 // _hasIndeterminateDimensions = true;
-            }
-            else
-            {
-                try
-                {
+            } else {
+                try {
                     dimensions[i] = Integer.parseInt(dimStrings[i]);
-                }
-                catch (Exception e)
-                {
+                } catch (Exception e) {
                     throw new XmlValueOutOfRangeException();
                 }
             }
         }
         SOAPArrayType sot = new SOAPArrayType();
-        sot._ranks = ranks;
+        sot._ranks = EMPTY_INT_ARRAY;
         sot._type = itemType;
         sot._dimensions = dimensions;
         return sot;
@@ -381,28 +310,20 @@
      * the default that is stored, outputs the soap arraySize
      * string.
      */
-    public String soap12DimensionString(int[] actualDimensions)
-    {
-        StringBuilder sb = new StringBuilder();
-
-        for (int i = 0; i < actualDimensions.length; i++)
-        {
-            if (i > 0)
-                sb.append(' ');
-            if (actualDimensions[i] >= 0)
-                sb.append(actualDimensions[i]);
-        }
-        return sb.toString();
+    public String soap12DimensionString(int[] actualDimensions) {
+        return IntStream.of(actualDimensions).
+            mapToObj(i -> (i >= 0) ? Integer.toString(i) : "").
+            collect(Collectors.joining(" "));
     }
 
     /**
      * Constructs a SOAPArrayType reflecting the dimensions
      * of the next nested array.
      */
-    public SOAPArrayType nestedArrayType()
-    {
-        if (!containsNestedArrays())
+    public SOAPArrayType nestedArrayType() {
+        if (!containsNestedArrays()) {
             throw new IllegalStateException();
+        }
 
         SOAPArrayType result = new SOAPArrayType();
 
@@ -412,46 +333,30 @@
         System.arraycopy(_ranks, 0, result._ranks, 0, result._ranks.length);
 
         result._dimensions = new int[_ranks[_ranks.length - 1]];
-        for (int i = 0; i < result._dimensions.length; i++)
-            result._dimensions[i] = -1;
+        Arrays.fill(result._dimensions, -1);
 
         // result._hasIndeterminateDimensions = (result._dimensions.length > 0);
 
         return result;
     }
 
-    public int hashCode()
-    {
+    public int hashCode() {
         return (_type.hashCode() + _dimensions.length + _ranks.length + (_dimensions.length == 0 ? 0 : _dimensions[0]));
     }
 
-    public boolean equals(Object obj)
-    {
-        if (obj == this)
+    public boolean equals(Object obj) {
+        if (obj == this) {
             return true;
+        }
 
-        if (!obj.getClass().equals(getClass()))
+        if (!(obj instanceof SOAPArrayType)) {
             return false;
+        }
 
-        SOAPArrayType sat = (SOAPArrayType)obj;
+        SOAPArrayType sat = (SOAPArrayType) obj;
 
-        if (!_type.equals(sat._type))
-            return false;
-
-        if (_ranks.length != sat._ranks.length)
-            return false;
-
-        if (_dimensions.length != sat._dimensions.length)
-            return false;
-
-        for (int i = 0; i < _ranks.length; i++)
-            if (_ranks[i] != sat._ranks[i])
-                return false;
-
-        for (int i = 0; i < _dimensions.length; i++)
-            if (_dimensions[i] != sat._dimensions[i])
-                return false;
-
-        return true;
+        return _type.equals(sat._type) &&
+               Arrays.equals(_ranks, sat._ranks) &&
+               Arrays.equals(_dimensions, sat._dimensions);
     }
 }