我写了一个调用常量类的 JUnit,在这里我们试图访问一个静态的最终列表
public static final List<String> SKIPPED_DIMENSION_LIST = new ArrayList<String>();
static{ SKIPPED_DIMENSION_LIST.add(PRODUCT_CATEGORY_DISPLAY);
SKIPPED_DIMENSION_LIST.add(PRODUCT_CATEGORY_SUB);
SKIPPED_DIMENSION_LIST.add(PRODUCT_CATEGORY_SUB_GROUP);
SKIPPED_DIMENSION_LIST.add(PRODUCT_CATEGORY_SUB_GROUP_ID);
SKIPPED_DIMENSION_LIST.add(PRODUCT_CATEGORY_ID);
SKIPPED_DIMENSION_LIST.add(PRODUCT_CATEGORY_GROUP_ID); }
现在,在通过 JUnit 线程访问这个列表时,我遇到了这个错误。
java.lang.ExceptionInInitializerError
at java.lang.J9VMInternals.initialize(J9VMInternals.java:222)
at com.mns.commerce.searchnav.constants.MSEndecaConstants.<clinit>(MSEndecaConstants.java:169)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
at com.mns.commerce.searchnav.utils.MSSearchResposeBOTransformer.getRefinementsDetails(MSSearchResposeBOTransformer.java:460)
at com.mns.commerce.searchnav.utils.MSSearchResposeBOTransformer.buildFacets(MSSearchResposeBOTransformer.java:362)
at com.mns.commerce.searchnav.utils.MSSearchResposeBOTransformer.populateResults(MSSearchResposeBOTransformer.java:106)
at com.mns.commerce.searchnavunit.test.MSSearchResposeBOTransformerTest.testPopulateResults(MSSearchResposeBOTransformerTest.java:97)
然而,如果Enum
定义了一个静态而不是一个,static final list
那么它工作正常。知道为什么会这样吗?