-2

I'm using the following function to take a large array of strings (user names) and check them for single quotes, then push them into my new array and return that.

Recently, the number of users in this list increased dramatically (7418 currently) and now this function is getting an error:

Caused by: java.lang.ClassFormatError: Invalid method Code length 105684 in class file org/mozilla/javascript/gen/c135516

The version of javascript is embedded in the application so upgrading that is not an option at this time.

Is there a better way to do this? or a different way to try to avoid this error?

function listExcludedUsers(rInactive) {
    var result = new Array('user1', 'user2', 'user3', 'user4');

    for (var i = 0; i < rInactive.length; i++) {
        //replace single quote with two single quotes for DQL
        if (rInactive[i].indexOf("'") > 0) {
            rInactive[i] = rInactive[i].replace(/'/g, "''");
        }
        result.push(rInactive[i]);
    }
    return result;
}
trueimage
  • 309
  • 2
  • 4
  • 14
  • 3
    `Caused by: java.lang.ClassFormatError` is a `Java` error not a `Javascript`one. So I don't think, `listExcludedUsers` have something to do with this. – service-paradis Nov 09 '15 at 21:28
  • In my experience with this application it is usually javascript causing the java failure, but yes you are correct. – trueimage Nov 09 '15 at 21:30
  • 1
    May be you can use object instead a array like: [enter link description here](http://stackoverflow.com/questions/16507222/create-json-object-dynamically-via-javascript-without-concate-strings) – Stefan Kanev Nov 09 '15 at 21:38
  • 1
    If the array really contains only 7418 entries, it should not be a problem. See this jsfiddle that create an array of 10000 entries, loop over it and replace every single quote by 2 single quotes. http://jsfiddle.net/4c11ue7L/ This should not cause this kind of problem. – service-paradis Nov 09 '15 at 21:42

2 Answers2

1

Thhe JVM restricts the length of methods to 65536 bytes, so it seems as if you have found a bug in Mozilla. Please file it (with example if possible) at https://bugzilla.mozilla.org/.

Meanwhile: try to cut your method in multiple smaller parts, e.g.: chop the input and push it into several smaller arrays and concatenate those at the end. You should do it with several different functions.

deamentiaemundi
  • 5,502
  • 2
  • 12
  • 20
  • Ok so I need to split up the initial list into smaller lists and join them in my function? – trueimage Nov 09 '15 at 21:42
  • Better: in several functions and use another one to join them all into the final array. But it is a try! No guarantee that it will work, but it's a quick hack done in a couple of minutes and hence worth that try. – deamentiaemundi Nov 09 '15 at 21:49
1

This code looks like you are running a jvm that does not take very long methods name and those methods are because of the JavaScript input you are giving, it would be nice to try to reproduce the case, I would

Try to change the input of your JavaScript code that makes those methods in jvm too longs, may be in several sets of inputs.

juan garcia
  • 1,326
  • 2
  • 23
  • 56