• Post Reply Bookmark Topic Watch Topic
  • New Topic

Probem in executing static method

sabyasachi Gupta
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a static method like this which does some string manupulation:
* This method returns a String contained within the first available
* set of opening and closing braces taking care of nested braces and quotes
* so given the String
* @ADD(@MUL(4,6), @DIV(8,2)) it will return @MUL(4,6), @DIV(8,2)
private static String getEnclosedString(String argExp) throws Exception {
int beginPos = -1;
int lastBracePos = -1;
int currentPos = -1;
int depth = 0;
boolean inQuotes=false;
boolean inBraces=false;
while (currentPos < argExp.length()-1) {
char currentChar = argExp.charAt(currentPos);
if ( currentChar=='\'' &&
currentPos<(argExp.length()-1) &&
) {
inQuotes = !inQuotes;
if ( currentChar=='(' && !inQuotes) {
Log.msg("DEPTH : "+depth);
if (beginPos == -1 ) beginPos = currentPos;
inBraces = true;
if ( currentChar==')' && !inQuotes) {
if (depth==0) {
lastBracePos = currentPos;
inBraces = false;
}//while more characters in the expression
//if (depth!=0) throw new Exception("Mismatched braces in expression ["+argExp+"]");
if (depth!=0) throw new Exception(hcySecGlobal.ERROR_MESSAGES[hcySecGlobal.ERR_MISMATCHED_BRACES] +argExp);

return argExp.substring(beginPos+1, lastBracePos);

Now this method works fine for all strings like @members('LEVEL') etc. But sometimes this method throws exception at the line throw new Exception(hcySecGlobal.ERROR_MESSAGES[hcySecGlobal.ERR_MISMATCHED_BRACES] +argExp);
Can anybody please explain why this is happening? This is a part of a application server code. A typical string is like @members('LEVEL'). If i make a stadalone program and execute the method this works fine. Even when this method is called in application server this works fine and then suddenly it begins to throw exception for strings which it has previously executed properly. The only option remains is to restart the java application server(This is our own socket server). Then again it starts working fine. can this be due to some memory related problem?
Ray Stojonic
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the exception shows a string with properly matched braces...well, I have to admit I didn't see anything obvious that would cause depth to not be == 0 at the end of the method.
If the comments are to be believed, why not simply say:

Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!