Skip to content

False positive FS_BAD_DATE_FORMAT_FLAG_COMBO with non-interpreted text #3387

@slafon51

Description

@slafon51

Hello,

When validating a date format (rule FS_BAD_DATE_FORMAT_FLAG_COMBO), non-interpreted texts seems to be taken into account by the validator.

Example :

The following code :

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

public class TestDateFormat {

    public String testDateFormat() {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d MMMM yyyy à HH'h'mm", Locale.FRENCH);
        return ZonedDateTime.now(ZoneId.systemDefault()).format(formatter);
    }
}

generate the following error :

[ERROR] Medium: The 'd MMMM yyyy à HH'h'mm' date format string may lead to unexpected behavior used in testDateFormat() At TestDateFormat.java:[line XX] FS_BAD_DATE_FORMAT_FLAG_COMBO

Without the non-interpreted text 'h', no errors are reported.

Reproduced with spotbugs-maven-plugin version 4.9.3.0.

Best regards.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions