Changeset 13697 in josm for trunk/src/org


Ignore:
Timestamp:
2018-05-01T21:45:53+02:00 (6 years ago)
Author:
Don-vip
Message:

see #16243 - fix introduced SonarQube issues

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/WindowsShortcut.java

    r13692 r13697  
    77import java.io.IOException;
    88import java.io.InputStream;
     9import java.nio.charset.StandardCharsets;
    910import java.text.ParseException;
     11import java.util.Locale;
    1012
    1113/**
     
    4648        try (InputStream fis = new FileInputStream(file)) {
    4749            isPotentiallyValid = file.isFile()
    48                 && file.getName().toLowerCase().endsWith(".lnk")
     50                && file.getName().toLowerCase(Locale.ENGLISH).endsWith(".lnk")
    4951                && fis.available() >= minimum_length
    5052                && isMagicPresent(getBytes(fis, 32));
     
    142144
    143145            // get the file attributes byte
    144             final int file_atts_offset = 0x18;
    145             byte file_atts = link[file_atts_offset];
    146             byte is_dir_mask = (byte) 0x10;
    147             if ((file_atts & is_dir_mask) > 0) {
     146            final int fileAttsOffset = 0x18;
     147            byte fileAtts = link[fileAttsOffset];
     148            byte isDirMask = (byte) 0x10;
     149            if ((fileAtts & isDirMask) > 0) {
    148150                isDirectory = true;
    149151            } else {
     
    152154
    153155            // if the shell settings are present, skip them
    154             final int shell_offset = 0x4c;
    155             final byte has_shell_mask = (byte) 0x01;
    156             int shell_len = 0;
    157             if ((flags & has_shell_mask) > 0) {
     156            final int shellOffset = 0x4c;
     157            final byte hasShellMask = (byte) 0x01;
     158            int shellLen = 0;
     159            if ((flags & hasShellMask) > 0) {
    158160                // the plus 2 accounts for the length marker itself
    159                 shell_len = bytesToWord(link, shell_offset) + 2;
     161                shellLen = bytesToWord(link, shellOffset) + 2;
    160162            }
    161163
    162164            // get to the file settings
    163             int file_start = 0x4c + shell_len;
    164 
    165             final int file_location_info_flag_offset_offset = 0x08;
    166             int file_location_info_flag = link[file_start + file_location_info_flag_offset_offset];
    167             isLocal = (file_location_info_flag & 2) == 0;
     165            int fileStart = 0x4c + shellLen;
     166
     167            final int fileLocationInfoFlagOffsetOffset = 0x08;
     168            int fileLocationInfoFlag = link[fileStart + fileLocationInfoFlagOffsetOffset];
     169            isLocal = (fileLocationInfoFlag & 2) == 0;
    168170            // get the local volume and local system values
    169             //final int localVolumeTable_offset_offset = 0x0C;
    170             final int basename_offset_offset = 0x10;
    171             final int networkVolumeTable_offset_offset = 0x14;
    172             final int finalname_offset_offset = 0x18;
    173             int finalname_offset = link[file_start + finalname_offset_offset] + file_start;
    174             String finalname = getNullDelimitedString(link, finalname_offset);
     171            final int basenameOffsetOffset = 0x10;
     172            final int networkVolumeTableOffsetOffset = 0x14;
     173            final int finalnameOffsetOffset = 0x18;
     174            int finalnameOffset = link[fileStart + finalnameOffsetOffset] + fileStart;
     175            String finalname = getNullDelimitedString(link, finalnameOffset);
    175176            if (isLocal) {
    176                 int basename_offset = link[file_start + basename_offset_offset] + file_start;
    177                 String basename = getNullDelimitedString(link, basename_offset);
     177                int basenameOffset = link[fileStart + basenameOffsetOffset] + fileStart;
     178                String basename = getNullDelimitedString(link, basenameOffset);
    178179                realFile = basename + finalname;
    179180            } else {
    180                 int networkVolumeTable_offset = link[file_start + networkVolumeTable_offset_offset] + file_start;
    181                 int shareName_offset_offset = 0x08;
    182                 int shareName_offset = link[networkVolumeTable_offset + shareName_offset_offset]
    183                     + networkVolumeTable_offset;
    184                 String shareName = getNullDelimitedString(link, shareName_offset);
     181                int networkVolumeTableOffset = link[fileStart + networkVolumeTableOffsetOffset] + fileStart;
     182                int shareNameOffsetOffset = 0x08;
     183                int shareNameOffset = link[networkVolumeTableOffset + shareNameOffsetOffset]
     184                    + networkVolumeTableOffset;
     185                String shareName = getNullDelimitedString(link, shareNameOffset);
    185186                realFile = shareName + "\\" + finalname;
    186187            }
     
    201202            len++;
    202203        }
    203         return new String(bytes, off, len);
     204        return new String(bytes, off, len, StandardCharsets.UTF_8);
    204205    }
    205206
Note: See TracChangeset for help on using the changeset viewer.