title: Static access of Enums in Java?
body: <p>I have two enums <code>AttributesProperty</code> and <code>ResourceAttributesMapping</code> each referencing each other as shown below:</p>
  <pre class="lang-java prettyprint-override"><code>import org.apache.commons.collections.map.HashedMap;
      
      import test.xsd.Attribute;
      
      public enum AttributesProperty {
          
          ACP_RESOURCETYPE(ResourceAttributesMapping.ACCESSCONTROLPOLICY,&quot;resourceType&quot;),
          ACP_RESOURCEID(ResourceAttributesMapping.ACCESSCONTROLPOLICY,&quot;resourceID&quot;),
      .............
      
      private ResourceAttributesMapping resource;
          private String attributeName;
      
          private AttributesProperty(ResourceAttributesMapping resource, String attributeName)
          {
              this.resource = resource;
              this.attributeName = attributeName;
          }
      
      public static Map&lt;ResourceAttributesMapping, List&lt;Attribute&gt;&gt; getResTypeMapForAttrName(List&lt;Attribute&gt; attributesList) {
      
          Map&lt;ResourceAttributesMapping, List&lt;Attribute&gt;&gt; attributeMap = new HashedMap();
          
          List&lt;Attribute&gt; attrList = null;
          List&lt;ResourceAttributesMapping&gt; resTypes = new ArrayList&lt;ResourceAttributesMapping&gt;();
          for (Attribute attr : attributesList) {
              boolean flag = false;
              for (AttributesProperty attrProp : AttributesProperty.values()) {
                  if (attr.getName().equals(attrProp.getAttributeName())) {
                      
                          if (attributeMap.get(attrProp.getResourceType()) == null) {
                              
                           .........// Some logic
      }
      
      }
  </code></pre>
  <p><strong>Referenced Enum: ResourceAttributesMapping.java</strong></p>
  <p>This enum as seen in imports statically importing the <code>AttributesProperty</code> enum.</p>
  <pre class="lang-java prettyprint-override"><code>import static xsd.enums.AttributesProperty.*;
  
  import java.math.BigInteger;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.List;
  import java.util.Map;
  
  import org.apache.commons.collections.map.HashedMap;
  
  
  public enum ResourceAttributesMapping
  {
      
      ACCESSCONTROLPOLICY(1, Arrays.asList(ACP_RESOURCETYPE,ACP_RESOURCEID,............)), 
      
      AE(2, Arrays.asList(AE_RESOURCETYPE,AE_RESOURCEID,...........)),
  
  ....
  
  private int resourceType;
      private List&lt;AttributesProperty&gt; attrList;
  
      private ResourceAttributesMapping(int resourceType, List&lt;AttributesProperty&gt; attrList) {
          this.resourceType = resourceType;
          this.attrList = attrList;
      }
  
      public int getM2MResourceTypes() {
          return resourceType;
      }
      
      public  List&lt;AttributesProperty&gt; getAttributeList(){
          return attrList;
      }
  
  ......// accessor methods
  }
  </code></pre>
  <p>This code was running succesfully on JDK 8, WildFly 15 but after migrating to JDK 11 WildFly 20, I am getting a <code>NullPointerException</code> in the <code>AttributesProperty</code> 's enums accessor method:</p>
  <pre class="lang-java prettyprint-override"><code>public static Map&lt;ResourceAttributesMapping, List&lt;Attribute&gt;&gt; getResTypeMapForAttrName(List&lt;Attribute&gt; attributesList) {
  
      Map&lt;ResourceAttributesMapping, List&lt;Attribute&gt;&gt; attributeMap = new HashedMap();
      
      List&lt;Attribute&gt; attrList = null;
      List&lt;ResourceAttributesMapping&gt; resTypes = new ArrayList&lt;ResourceAttributesMapping&gt;();
      for (Attribute attr : attributesList) {
          boolean flag = false;
          for (AttributesProperty attrProp : AttributesProperty.values()) {
              if (attr.getName().equals(attrProp.getAttributeName())) {
                  
                      if (attributeMap.get(attrProp.getResourceType()) == null) {
                          
                       .........// Some logic
  </code></pre>
  <p><code>attrProp.getResourceType()</code> is giving <code>null</code>.</p>
  <p>The test scenario is such that on first iteration of running the accesor methods in the enum it runs successfully, however on second iteration I get the <code>NullPointerException</code>.</p>
  <p>Is there some change in Enums accessing from JDK 8 to 11?</p>
  <p>Or the static access of second enum causing the issue.</p>