Issue #23507 Several fixes

- with these fixes tests passed also in Eclipse editor, not just on command line
- envProperties can be null (no asenv.conf used)
- RepositoryConfig - contains suspicious code, I'm not changing the behavior
  despite it looks like a bug until I will have tests for clusters
- StringSubstitutionEngine - inputStream field was unused except constructor
- StringSubstitutionParser - javadoc now mentions that stream is closed after
  parsing
diff --git a/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/DomainConfig.java b/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/DomainConfig.java
index 94d3b0a..a209063 100644
--- a/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/DomainConfig.java
+++ b/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/DomainConfig.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018-2021 Oracle and/or its affiliates. All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v. 2.0, which is available at
@@ -81,7 +81,9 @@
             // net to get fully qualified host, not just hostname
             ASenvPropertyReader pr = new ASenvPropertyReader();
             Map<String, String> envProperties = pr.getProps();
-            put(K_HOST_NAME, envProperties.get(SystemPropertyConstants.HOST_NAME_PROPERTY));
+            if (envProperties != null) {
+                put(K_HOST_NAME, envProperties.get(SystemPropertyConstants.HOST_NAME_PROPERTY));
+            }
         } catch (Exception ex) {
             throw new DomainException(ex);
         }
diff --git a/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/RepositoryConfig.java b/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/RepositoryConfig.java
index a4dcdff..e48d38f 100644
--- a/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/RepositoryConfig.java
+++ b/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/RepositoryConfig.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018-2021 Oracle and/or its affiliates. All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v. 2.0, which is available at
@@ -31,43 +31,53 @@
 import com.sun.enterprise.universal.glassfish.ASenvPropertyReader;
 
 /**
- * This class represents a repository configuration. A repository can be either a domain, a node agent, or a server
- * instance. Configuration specific to each (DomainConfig, AgentConfig, InstanceConfig) is derived from this class. A
- * repository config consists of the following attributes:
+ * This class represents a repository configuration. A repository can be either a domain, a node
+ * agent, or a server
+ * instance. Configuration specific to each (DomainConfig, AgentConfig, InstanceConfig) is derived
+ * from this class.
  *
- * 1)repositoryName -- domain or node agent name (e.g. domain1 or agent1)
+ * A repository config consists of the following attributes:
+ * <ol>
+ * <li>repositoryName -- domain or node agent name (e.g. domain1 or agent1)
+ * <li>repositoryRoot -- the parent directory of the repository (e.g. $installDir/domains or
+ * $installDir/agents)
+ * <li>instanceName -- the optional server instance name (e.g. server1)
+ * <li>configurationName -- the optional configuration name of the server instance (e.g.
+ * default-config).
+ * </ol>
  *
- * 2)repositoryRoot -- the parent directory of the repository (e.g. $installDir/domains or $installDir/agents)
- *
- * 3)instanceName -- the optional server instance name (e.g. server1)
- *
- * 4)configurationName -- the optional configuration name of the server instance (e.g. default-config).
- *
- * Using (repositoryName, repositoryRoot, instanceName, configurationName) syntax. Here are the following permutations:
- *
- * 1)For a domain: (domainRootDirectory, domainName, null, null) e.g. ("/sun/appserver/domains", "domain1", null, null)
- *
- * 2)For a node agent: (agentRootDirectory, agentName, "agent", null) e.g ("/sun/appserver/agents", "agent1", "agent",
+ * Using (repositoryName, repositoryRoot, instanceName, configurationName) syntax. Here are the
+ * following permutations:
+ * <ol>
+ * <li>For a domain: (domainRootDirectory, domainName, null, null) e.g. ("/sun/appserver/domains",
+ * "domain1", null, null)
+ * <li>For a node agent: (agentRootDirectory, agentName, "agent", null) e.g
+ * ("/sun/appserver/agents", "agent1", "agent",
  * null). Note that the instance name of a node agent is always the literal string "agent".
- *
- * 3)For a server instance (agentRootDirectory, agentName, instanceName, configName) e.g. ("/sun/appserver/agents",
+ * <li>For a server instance (agentRootDirectory, agentName, instanceName, configName) e.g.
+ * ("/sun/appserver/agents",
  * "agent1", "server1", "default-config")
+ * </ol>
  *
- * The RepositoryConfig class is an extensible HashMap that can contain any attributes, but also relies on two system
+ * The RepositoryConfig class is an extensible HashMap that can contain any attributes, but also
+ * relies on two system
  * properties being set:
- *
- * 1)com.sun.aas.installRoot -- installation root directory stored under the K_INSTALL_ROOT key.
- *
- * 2)com.sun.aas.configRoot -- configuration root (for locating asenv.conf) stored under the K_CONFIG_ROOT key.
+ * <ol>
+ * <li>com.sun.aas.installRoot -- installation root directory stored under the K_INSTALL_ROOT key.
+ * <li>com.sun.aas.configRoot -- configuration root (for locating asenv.conf) stored under the
+ * K_CONFIG_ROOT key.
+ * </ol>
  *
  * @author kebbs
  */
 public class RepositoryConfig extends HashMap<String, Object> {
+    private static final long serialVersionUID = 1L;
+
     public static final String K_INSTALL_ROOT = "install.root";
     public static final String K_CONFIG_ROOT = "config.root";
     public static final String K_REFRESH_CONFIG_CONTEXT = "refresh.cc";
     //Name of the domain or node agent. Cannot be null.
-    private String _repositoryName;
+    private final String _repositoryName;
     //Root directory where the domain or node agent resides. Cannot be null
     private String _repositoryRoot;
     //Name of the server instance. May be null
@@ -84,17 +94,16 @@
         _repositoryRoot = repositoryRoot;
         _configurationName = configName;
         final Map<String, String> envProperties = getEnvProps();
-        put(K_INSTALL_ROOT, getFilePath(envProperties.get(SystemPropertyConstants.INSTALL_ROOT_PROPERTY)));
-        //SystemPropertyConstants.INSTALL_ROOT_PROPERTY));
-        put(K_CONFIG_ROOT, getFilePath(envProperties.get(SystemPropertyConstants.INSTALL_ROOT_PROPERTY)));
-        //SystemPropertyConstants.CONFIG_ROOT_PROPERTY));
+
+        // Since the changes for the startup, we have the problem of refreshing
+        // config context. So, by default, I am making a change to refresh the
+        // config context. If some processes (e.g. start-domain) have already
+        // created a config context, then they should explicitly say so.
         put(K_REFRESH_CONFIG_CONTEXT, true);
-        /*
-         * Since the changes for the startup, we have the problem of refreshing
-         * config context. So, by default, I am making a change to refresh the
-         * config context. If some processes (e.g. start-domain) have already
-         * created a config context, then they should explicitly say so.
-         */
+        if (envProperties != null) {
+            put(K_INSTALL_ROOT, getFilePath(envProperties.get(SystemPropertyConstants.INSTALL_ROOT_PROPERTY)));
+            put(K_CONFIG_ROOT, getFilePath(envProperties.get(SystemPropertyConstants.INSTALL_ROOT_PROPERTY)));
+        }
     }
 
     public RepositoryConfig(String repositoryName, String repositoryRoot, String instanceName) {
@@ -121,10 +130,13 @@
         _repositoryRoot = FileUtils.makeForwardSlashes(repositoryDir.getParentFile().getAbsolutePath());
         _configurationName = null;
         final Map<String, String> envProperties = getEnvProps();
-        put(K_INSTALL_ROOT, envProperties.get(SystemPropertyConstants.INSTALL_ROOT_PROPERTY));
-        put(K_CONFIG_ROOT, getFilePath(envProperties.get(SystemPropertyConstants.CONFIG_ROOT_PROPERTY)));
+        if (envProperties != null) {
+            put(K_INSTALL_ROOT, envProperties.get(SystemPropertyConstants.INSTALL_ROOT_PROPERTY));
+            put(K_CONFIG_ROOT, getFilePath(envProperties.get(SystemPropertyConstants.CONFIG_ROOT_PROPERTY)));
+        }
     }
 
+    @Override
     public String toString() {
         return ("repositoryRoot " + _repositoryRoot + " repositoryName " + _repositoryName + " instanceName " + _instanceName
                 + " configurationName " + _configurationName);
diff --git a/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/stringsubs/impl/StringSubstitutionEngine.java b/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/stringsubs/impl/StringSubstitutionEngine.java
index cd76f6c..b024deb 100644
--- a/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/stringsubs/impl/StringSubstitutionEngine.java
+++ b/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/stringsubs/impl/StringSubstitutionEngine.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2018-2021 Oracle and/or its affiliates. All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v. 2.0, which is available at
@@ -58,7 +58,6 @@
     private static final Logger _logger = SLogger.getLogger();
 
     private static final LocalStringsImpl _strings = new LocalStringsImpl(StringSubstitutionEngine.class);
-    private InputStream _configInputStream = null;
 
     //Root of JAXB parsed string-subs configuration
     private StringsubsDefinition _root = null;
@@ -78,8 +77,7 @@
         if (inputStream == null) {
             throw new StringSubstitutionException("InputStream is null");
         }
-        _configInputStream = inputStream;
-        _root = StringSubstitutionParser.parse(_configInputStream);
+        _root = StringSubstitutionParser.parse(inputStream);
     }
 
     @Override
@@ -106,7 +104,7 @@
         if (type == null) {
             return defaults.getProperty();
         }
-        List<Property> props = new ArrayList<Property>();
+        List<Property> props = new ArrayList<>();
         for (Property prop : defaults.getProperty()) {
             if (prop.getType().equals(type)) {
                 props.add(prop);
@@ -199,7 +197,7 @@
             groupMode = modeType.value();
         }
         buildChangePairsMap();
-        Map<String, String> substitutionMap = new HashMap<String, String>();
+        Map<String, String> substitutionMap = new HashMap<>();
         for (ChangePairRef ref : refList) {
             String name = ref.getName();
             String localMode = ref.getMode();
@@ -271,14 +269,14 @@
             if (defaults != null) {
                 List<Property> properties = defaults.getProperty();
                 if (!properties.isEmpty()) {
-                    _defaultProperties = new HashMap<String, Property>(properties.size(), 1);
+                    _defaultProperties = new HashMap<>(properties.size(), 1);
                     for (Property prop : properties) {
                         _defaultProperties.put(prop.getKey(), prop);
                     }
                 }
             }
             List<? extends ChangePair> changePairList = _root.getChangePair();
-            _changePairsMap = new HashMap<String, Pair>(changePairList.size());
+            _changePairsMap = new HashMap<>(changePairList.size());
             for (ChangePair pair : _root.getChangePair()) {
                 String id = pair.getId();
                 String beforeValue = pair.getBefore();
diff --git a/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/stringsubs/impl/StringSubstitutionParser.java b/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/stringsubs/impl/StringSubstitutionParser.java
index a6b7f09..44ff1c5 100644
--- a/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/stringsubs/impl/StringSubstitutionParser.java
+++ b/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/stringsubs/impl/StringSubstitutionParser.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2018-2021 Oracle and/or its affiliates. All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v. 2.0, which is available at
@@ -51,13 +51,12 @@
     private final static String DEFAULT_SCHEMA = "xsd/schema/stringsubs.xsd";
 
     /**
-     * Parse the configuration stream against the string-subs schema.
+     * Parse the configuration stream against the string-subs schema and then closes the stream.
      *
      * @param configStream InputStream of stringsubs.xml file.
      * @return Parsed Object.
      * @throws StringSubstitutionException If any error occurs in parsing.
      */
-    @SuppressWarnings("rawtypes")
     public static StringsubsDefinition parse(InputStream configStream) throws StringSubstitutionException {
         // If schema information is missing
         if (configStream == null) {
@@ -73,20 +72,19 @@
             InputSource is = new InputSource(configStream);
             SAXSource source = new SAXSource(is);
             Object obj = unmarshaller.unmarshal(source);
-            return obj instanceof JAXBElement ? (StringsubsDefinition) ((JAXBElement) obj).getValue() : (StringsubsDefinition) obj;
+            return obj instanceof JAXBElement
+                ? (StringsubsDefinition) ((JAXBElement<?>) obj).getValue()
+                : (StringsubsDefinition) obj;
         } catch (SAXException se) {
             throw new StringSubstitutionException(_strings.get("failedToParse", DEFAULT_SCHEMA), se);
         } catch (JAXBException jaxbe) {
             throw new StringSubstitutionException(_strings.get("failedToParse", DEFAULT_SCHEMA), jaxbe);
         } finally {
-            if (configStream != null) {
-                try {
-                    configStream.close();
-                    configStream = null;
-                } catch (IOException e) {
-                    if (_logger.isLoggable(Level.FINER)) {
-                        _logger.log(Level.FINER, _strings.get("errorInClosingStream"));
-                    }
+            try {
+                configStream.close();
+            } catch (IOException e) {
+                if (_logger.isLoggable(Level.FINER)) {
+                    _logger.log(Level.FINER, _strings.get("errorInClosingStream"));
                 }
             }
         }