Repository: microsoft/gctoolkit
File: parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/Decorators.java (Java)

Code before:

    int numberOfDecorators;

    private String[] decoratorGroups;
    private String tags;

    public Decorators(String line) {
        extractValues(line);
    }

    private void extractValues(String line) {
        if (!line.startsWith("["))
            return;

        Matcher decoratorMatcher = UnifiedLoggingTokens.DECORATORS.matcher(line);
        if (!decoratorMatcher.find()) {
            return;
        }

        // Retrieving a group from a matcher calls substring each time
        // Store all the groups in an array ahead of time to avoid paying this cost unnecessarily
        decoratorGroups = new String[11];
        for (int i = 1; i <= decoratorMatcher.groupCount(); i++) {
            String group = decoratorMatcher.group(i);
            decoratorGroups[i] = group;
            if ( group != null)
                numberOfDecorators++;
        }
    }

    // For some reason, ISO_DATE_TIME doesn't like that time-zone is -0100. It wants -01:00.
    private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ");

    public ZonedDateTime getDateStamp() {
        try {
            String value = decoratorGroups[1];
            if (value != null) {
                TemporalAccessor temporalAccessor = formatter.parse(value.substring(1, value.length()-1));
                return ZonedDateTime.from(temporalAccessor);
            }
        } catch (NullPointerException npe) {
            LOGGER.log(Level.SEVERE, npe.getMessage(), npe);
        }
        return null;
    }

    public double getUpTime() {
        String value = decoratorGroups[2];
        if (value != null) {
            value = value.replace(",", ".");
            return Double.parseDouble(unboxValue(value, 1));

Review comment (suggestion):
```suggestion
            if (group != null)
```

Code after:

    private static final int DATE_STAMP_GROUP = 0;
    private static final int UPTIME_GROUP = 1;
    private static final int TIME_MILLIS_OR_MAYBE_UPTIME_MILLIS_GROUP = 2;
    private static final int UPTIME_MILLIS_GROUP = 3;
    private static final int TIME_NANOS_OR_MAYBE_UPTIME_NANOS_GROUP = 4;
    private static final int UPTIME_NANOS_GROUP = 5;
    private static final int PID_GROUP = 6;
    private static final int TID_GROUP = 7;
    private static final int LOG_LEVEL_GROUP = 8;
    private static final int TAGS_GROUP = 9;

    int numberOfDecorators;

    private String[] decoratorGroups;
    private String tags;

    public Decorators(String line) {
        extractValues(line);
    }

    private void extractValues(String line) {
        if (!line.startsWith("["))
            return;

        Matcher decoratorMatcher = UnifiedLoggingTokens.DECORATORS.matcher(line);
        if (!decoratorMatcher.find()) {
            return;
        }

        // Retrieving a group from a matcher calls substring each time
        // Store all the groups in an array ahead of time to avoid paying this cost unnecessarily
        decoratorGroups = new String[decoratorMatcher.groupCount()];
        for (int i = 1; i <= decoratorMatcher.groupCount(); i++) {
            String group = decoratorMatcher.group(i);
            decoratorGroups[i-1] = group;
            if (group != null)
                numberOfDecorators++;
        }
    }

    // For some reason, ISO_DATE_TIME doesn't like that time-zone is -0100. It wants -01:00.
    private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ");

    public ZonedDateTime getDateStamp() {
        try {
            String value = decoratorGroups[DATE_STAMP_GROUP];
            if (value != null) {
                TemporalAccessor temporalAccessor = formatter.parse(value.substring(1, value.length()-1));
                return ZonedDateTime.from(temporalAccessor);
            }