Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-48869

CsharpNamespaceDetector does not recognize "namespace" preceded by UTF-8 BOM


    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • analysis-core-plugin
    • Jenkins 2.89.2
      Static Analysis Utilities 1.93
      Warnings Plug-in 4.64

      If there are some compiler warnings about a C# source file that is encoded in UTF-8 and starts with a Byte Order Mark, and the BOM is immediately followed by "namespace " and the name of the namespace, then the Warnings Plug-in does not recognize the namespace declaration and instead displays the relative directory name.

      If I insert CRLF between the BOM and "namespace", then the Warnings Plug-in correctly displays the name of the namespace. Likewise, the namespace detector works OK if there is a comment with copyright notices at the top of the file.

      Because I cannot find any namespace detection code in the Warnings Plug-in itself, I believe the problem is in the hudson.plugins.analysis.util.CsharpNamespaceDetector class, defined in Static Analysis Utilities aka analysis-core. It decodes the file as UTF-8 and then checks each line against the regexp "^namespace .*$" until it finds a match. Perhaps this can be changed to allow "\uFEFF" at the start of the line, or more generally whitespace.

            drulli Ulli Hafner
            kon Kalle Niemitalo
            0 Vote for this issue
            2 Start watching this issue