christiangalsterer / stash-filehooks-plugin

An Atlassian Stash plugin to check on various file attributes, like size, name
Apache License 2.0
14 stars 27 forks source link

Passing integer to file size hook via rest api fails with java.lang.ClassCastException #19

Closed kbrnsr closed 7 years ago

kbrnsr commented 8 years ago

Using python and Bitbucket Server 4.2.0 (see exception log for more info)

I tried passing the following dict (gets converted to JSON) to the generic "enable" endpoint for hooks:

{u'pattern-1': u'.*',
u'size-1': 100000,
u'pattern-exclude-1': '',
u'pattern-branches-1': ''}

The problem is that "size-1" is an integer and not a string which makes the validation fail, the logs indicate that line 46 in FileSizeHookValidator.java is the problem:

try {
    int size = Integer.parseInt(settings.getString(SETTINGS_SIZE_PREFIX + i, ""));
    if (size < 1) {
        errors.addFieldError("size-" + i, i18n.getText("filesize-hook.error.size", "Size must be an integer value larger than 0"));
    }
} catch (NumberFormatException e) {
    errors.addFieldError(SETTINGS_SIZE_PREFIX + i, i18n.getText("filesize-hook.error.size", "Size must be an integer value larger than 0"));
}
christiangalsterer commented 8 years ago

Can you please try to use a string for the size instead of an int, like in the following example?

{u'pattern-1': u'.*',
u'size-1': '100000',
u'pattern-exclude-1': '',
u'pattern-branches-1': ''}

I think it should work then.

kbrnsr commented 8 years ago

I've already fixed the problem by converting the parameter to string, but the plugin should give some kind of error message if the exception occurs instead of getting a 5xx error (this is the acual issue) from the rest api