Uploaded image for project: 'SmartSprites'
  1. SmartSprites
  2. SMARTSPRITES-74

Negative values of sprite-margin cause java.lang.ArrayIndexOutOfBoundsException

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 0.2.6
    • Fix Version/s: 0.2.7
    • Labels:
      None

      Description

      If in the css file we put a negative value to sprite-margin-XXXX it throws a ArrayIndexOutOfBoundsException.

      I tried to fix it in source code. My changes affects the 3 files:

      org.carrot2.labs.smartsprites.message.Message
      ----------------------------------------------
      -added in MessageType :

      CANNOT_PARSE_NEGATIVE_MARGIN_VALUE("Cannot parse negative margin value: %s. Using '0'"),

      org.carrot2.labs.smartsprites.SpriteImageDirective
      -------------------------------------------------------
      -added a parameter "MessageLog messageLog" in SpriteImageDirective function. So the functions is like:

      public SpriteImageDirective(String id, String imageUrl, SpriteImageLayout layout,
      SpriteImageFormat format, Ie6Mode ie6Mode, Color matteColor, SpriteUidType uidType, MessageLog messageLog)

      { this(id, imageUrl, layout, format, ie6Mode, matteColor, uidType, new SpriteLayoutProperties(layout, messageLog)); }

      org.carrot2.labs.smartsprites.SpriteLayoutProperties
      -----------------------------------------------------
      -changes in the 2 constructors:

      public SpriteLayoutProperties(SpriteAlignment alignment, int marginLeft,
      int marginRight, int marginTop, int marginBottom, MessageLog messageLog)
      {
      this.alignment = alignment;
      if(marginLeft<0)

      { messageLog.warning(MessageType.CANNOT_PARSE_NEGATIVE_MARGIN_VALUE, marginLeft); this.marginLeft = 0; }

      else

      { this.marginLeft = marginLeft; }

      if(marginRight<0)

      { messageLog.warning(MessageType.CANNOT_PARSE_NEGATIVE_MARGIN_VALUE, marginRight); this.marginRight = 0; }

      else

      { this.marginRight = marginRight; }

      if(marginTop<0)

      { messageLog.warning(MessageType.CANNOT_PARSE_NEGATIVE_MARGIN_VALUE, marginTop); this.marginTop = 0; }

      else

      { this.marginTop = marginTop; }

      if(marginBottom<0)

      { messageLog.warning(MessageType.CANNOT_PARSE_NEGATIVE_MARGIN_VALUE, marginBottom); this.marginBottom = 0; }

      else

      { this.marginBottom = marginBottom; }

      }

      /**

      • Creates an instance with default values.
        */
        SpriteLayoutProperties(SpriteImageLayout layout, MessageLog messageLog) { this(getDefaultAlignment(layout), 0, 0, 0, 0, messageLog); }

      -added the parameter in the call in 'parse' method (line 129):

      return parse(directiveString, spriteImageLayout, new SpriteLayoutProperties(
      spriteImageLayout, messageCollector), messageCollector);

      -added the parameter in the call in 'parse' method (line 181):

      return new SpriteLayoutProperties(alignment, marginLeft, marginRight, marginTop,
      marginBottom);

      -Change the try/catch content in getMargin metod (line 246):

      try
      {
      int value = Integer.parseInt(marginValue);
      if (value<0)

      { messageLog.warning(MessageType.CANNOT_PARSE_NEGATIVE_MARGIN_VALUE, rawMarginValue); return 0; }

      else

      { return value; }

      }
      catch (final NumberFormatException e)

      { messageLog.warning(MessageType.CANNOT_PARSE_MARGIN_VALUE, rawMarginValue); return 0; }

        Attachments

        1. ENFSmartsprites.java
          1 kB
        2. ENFSmartsprites.java
          1 kB
        3. Message.java
          10 kB
        4. smart-sprites-examples.zip
          17 kB
        5. smart-sprites-examples.zip
          17 kB
        6. SpriteImageDirective.java
          11 kB
        7. SpriteLayoutProperties.java
          10 kB

          Activity

            People

            • Assignee:
              stachoo Stanisław Osiński
              Reporter:
              alejandro alejandro anadon
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 0h
                0h
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 19m
                19m