Enum reverse lookup thread safety

Description

Enums with a reverse value lookup are not thread safe, e.g. EAccessLevel:

private final static Map<String, EAccessLevel> ID_MAP = new HashMap<>(); @Nullable public static EAccessLevel getAccessLevel(@Nullable String identifier) { if (ID_MAP.isEmpty()) { for (EAccessLevel accessLevel : values()) { ID_MAP.put(accessLevel.getIdentifier(), accessLevel); } } return ID_MAP.get(identifier); }

could return null for existing identifier with multiple threads accessing it. Replace with a ReverseMap like in HtmlDoctype

Activity

Show:

Edoardo Beutler 21 February 2017 at 16:37

Bad merge:

  1. Code did not compile!
    This merge removed a required

    import com.google.common.base.Strings;

    in MetaTagScriptService which lead to compile errors and failing Jenkins builds.

  2. After fixing that, code still does not compile, since 10 tests are failing:

    Failed tests: ECharsetTest.testGetCharset:22 EHttpEquivTest.testGetHttpEquiv:22 expected:<CONTENT_SECURITY_POLICY> but was:<Optional.of(CONTENT_SECURITY_POLICY)> ENameNonStandardTest.testGetName:24 expected:<CREATOR> but was:<Optional.of(CREATOR)> ENameStandardTest.testGetName:24 expected:<APPLICATION_NAME> but was:<Optional.of(APPLICATION_NAME)> EReferrerTest.testGetReferrer:17 expected:<NO_REFFERER> but was:<Optional.of(NO_REFFERER)> ERobotTest.testGetRobot:21 expected:<INDEX> but was:<Optional.of(INDEX)> EViewportTest.testGetViewport:18 expected:<HEIGHT> but was:<Optional.of(HEIGHT)> EOpenGraphTest.testGetOpenGraph:30 expected:<OPENGRAPH_TITLE> but was:<Optional.of(OPENGRAPH_TITLE)> ETwitterCardTypeTest.testGetTwitterCardType:16 expected:<SUMMARY> but was:<Optional.of(SUMMARY)> ETwitterTest.testGetTwitter:28 expected:<TWITTER_CARD> but was:<Optional.of(TWITTER_CARD)>

Marc Sladek 14 February 2017 at 10:36

PR reviewed, changes requested

Marc Sladek 7 February 2017 at 18:18
Edited

in the future please add pull request to jira issue and start testing with reviewer assigned

Marc Sladek 7 February 2017 at 18:17

Done

Details

Priority

Assignee

Reporter

Story Points

Sprint

Fix versions

Clockify

Created 7 February 2017 at 13:05
Updated 29 March 2017 at 16:47
Resolved 9 March 2017 at 14:49