I believe I have seen this too, when I've seen (and my experience is very limited) a local variable with a length of 0 then it meant the method you are looking at ends in a local variable declaration, eg:
Public void somemethod() { ... Object o = new Object(); } The local variable o has a length of 0 instructions, at least that's what I understand. Mac -----Original Message----- From: Arrin Daley [mailto:[EMAIL PROTECTED] Sent: 14 August 2007 03:56 To: BCEL Users List Subject: Re: getLocalVariable returns null but appears to exist Hi Eric LocalVariableTables like LineNumberTables are an optional attribute to JavaClass, they don't have to exist and if they do exist they don't have to be correct. It depends what you are doing if you are generating the code that you the snippet is working on then that's OK you can trust the LocalVaraibleTable (provided you built it correctly) but if the code comes from elsewhere then I suggest that the LocalVariableTable could contain anything or not exist at all. As for why it is returning null, I had a look at the BCEL source (available online): 143 public final LocalVariable getLocalVariable( int index, int pc ) { 144 for (int i = 0; i < local_variable_table_length; i++) { 145 if (local_variable_table[i].getIndex() == index) { 146 int start_pc = local_variable_table[i].getStartPC(); 147 int end_pc = start_pc + local_variable_table[i].getLength(); 148 if ((pc >= start_pc) && (pc < end_pc)) { 149 return local_variable_table[i]; 150 } 151 } 152 } 153 return null; 154 } line 148 has the test (pc >= start_pc) && (pc < end_pc) with a length of zero the pc cannot be less than the end_pc so therefore it doesn't find the localvariable and returns null. A way to get around it might be to request the LocalVariableTable as a LocalVariable[] and then search the LocalVariable array yourself. Hope it helps Bye Arrin Eric Sheridan wrote: >Group, > >I am calling the following code snippet: > >StoreInstruction si = (StoreInstruction)instruction; >int index = si.getIndex(); >int pc = ihs[i].getPosition() + 2; >LocalVariable lv = lvt.getLocalVariable(index, pc); > >if(lv == null) >{ > System.out.println("[ERROR] unable to locate assigned variable name. "); > System.out.println("[*] pc " + pc + " index " + index); > System.out.println(lvt.toString()); > return; >} > >The result of "getLocalVariable" is null for a particular local variable and I cant figure out why. Below is a result of the 'System.out.println()'s' found in the previous code segment: > >[ERROR] unable to locate assigned variable name. >[*] pc 472 index 6 >LocalVariable(start_pc = 346, length = 76, index = 11:int i) >LocalVariable(start_pc = 266, length = 201, index = 6:String[] fields) >LocalVariable(start_pc = 277, length = 190, index = 7:int id) >LocalVariable(start_pc = 311, length = 156, index = 8:org.apache.ecs.html.Table t) >LocalVariable(start_pc = 334, length = 133, index = 9:org.apache.ecs.html.TR header) >LocalVariable(start_pc = 343, length = 124, index = 10:org.apache.ecs.html.TR results) >LocalVariable(start_pc = 472, length = 0, index = 6:Exception e) >LocalVariable(start_pc = 485, length = 103, index = 6:org.apache.ecs.html.A a) >LocalVariable(start_pc = 593, length = 34, index = 6:Exception e) >LocalVariable(start_pc = 0, length = 629, index = 0:org.owasp.webgoat.lessons.WSDLScanning this) >LocalVariable(start_pc = 0, length = 629, index = 1:org.owasp.webgoat.session.WebSession s) >LocalVariable(start_pc = 8, length = 621, index = 2:org.apache.ecs.ElementContainer ec) >LocalVariable(start_pc = 24, length = 605, index = 3:org.apache.ecs.html.Table t1) >LocalVariable(start_pc = 46, length = 583, index = 4:org.apache.ecs.html.TR tr) >LocalVariable(start_pc = 218, length = 411, index = 5:org.apache.ecs.Element b) > >The variable appears to exist (the line - LocalVariable(start_pc = 472, length = 0, index = 6:Exception e) ) but >getLocalVariable returns null. Any ideas why? Does "length = 0" have any significance? > >As usual, thanks in advance for everyones input! > >-Eric > > > -- Conventional wisdom says to know your limits. To know your limits you need to find them first. Finding you limits generally involves getting in over your head and hoping you live long enough to benefit from the experience. That's the fun part. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]