[Dev] Patch: NPE in ScriptRunner.methodFromCall(ScriptRunner.java:239)

Frank Cohen fcohen at pushtotest.com
Fri Oct 5 15:48:23 PDT 2007


Dear William and Luis Carlos:

I will open a ticket on the issue Lars raises.

Please take a look at the issue Lars raises and respond to the list  
with your ideas.

Thanks.

-Frank

On Oct 1, 2007, at 9:30 PM, Lars Huttar wrote:

> On 9/28/2007 5:45 PM, Olivier Dony wrote:
>> On Sep 29, 2007, at 12:25 AM, Lars Huttar wrote:
>>
>>> Well, that particular error was apparently caused by the fact  
>>> that I was missing a langtype attribute on my <run> element:
>>>                                                          <run  
>>> module="ethnunit" name="test1" testclass="HTTPExample"  
>>> method="runtest" />
>>>
>>> After supplying langtype="jython", that particular NPE goes away.
>>> Hopefully that could be fixed to tell the user they're missing a  
>>> langtype attribute, if it is indeed required.
>>>
>>> Now I get a different set of errors:
>>>
>>> java.lang.NullPointerException
>>>    at java.io.FileInputStream.<init>(Unknown Source)
>>>    at java.io.FileInputStream.<init>(Unknown Source)
>>>    at java.io.FileReader.<init>(Unknown Source)
>>>    at  
>>> com.pushtotest.testmaker.XSTest.xml.TestScenario.ScriptRunner.argume 
>>> ntsFormCallScript(ScriptRunner.java:488)
>>>    at  
>>> com.pushtotest.testmaker.XSTest.xml.TestScenario.ScriptRunner.argume 
>>> ntsFromCall(ScriptRunner.java:421)
>>>    at  
>>> com.pushtotest.testmaker.XSTest.xml.TestScenario.ScriptRunner.setupM 
>>> ethodForTest(ScriptRunner.java:225)
>>>    at  
>>> com.pushtotest.testmaker.XSTest.xml.TestScenario.ScriptRunner.setMet 
>>> hods(ScriptRunner.java:213)
>>>    at  
>>> com.pushtotest.testmaker.XSTest.xml.TestScenario.ScriptRunner.<init> 
>>> (ScriptRunner.java:192)
>>>    at  
>>> com.pushtotest.testmaker.XSTest.xml.TestScenario.TestusecaseRunner.r 
>>> unOneTime(TestusecaseRunner.java:381)
>>>    at  
>>> com.pushtotest.testmaker.XSTest.xml.TestScenario.TestscenarioRunner. 
>>> runFunctionaltest(TestscenarioRunner.java:288)
>>>    at  
>>> com.pushtotest.testmaker.XSTest.xml.TestScenario.TestscenarioRunner. 
>>> access$000(TestscenarioRunner.java:91)
>>>    at  
>>> com.pushtotest.testmaker.XSTest.xml.TestScenario.TestscenarioRunner$ 
>>> FunctionalTest.run(TestscenarioRunner.java:272)
>>
>> Could it be that the ScriptRunner cannot access your script file?  
>> Maybe something to do with the way the file path is written?
>>
> Turns out that the problem here is that the script runner class was  
> opening the script file, catching exceptions, and ignoring them. :-(
> So when the problem bites you later, all you get is the NPE.
>
> Attached is a patch to fix this, and the other problem (missing  
> langtype not caught).
> Also, a typo fixed in the method name "argumentsFormCallScript()".
>
> My fix for the missing langtype attribute is probably not ideal...  
> I tested for it everywhere that I could see it would cause a NPE.
> Probably would be better to test for it when the <run> element is  
> first processed, and reject it if there is no langtype attribute.
> But I don't know where to find that.
>
> Note also, I have not yet been able to build TestMaker from source,  
> so I don't know for sure that this patch compiles or works.
>
> Lars
>
>
> *** TestMaker/src/com/pushtotest/testmaker/XSTest/xml/TestScenario/ 
> ScriptRunner.java.orig	Mon Aug 13 11:35:00 2007
> --- TestMaker/src/com/pushtotest/testmaker/XSTest/xml/TestScenario/ 
> ScriptRunner.java	Mon Oct  1 17:28:33 2007
> ***************
> *** 236,241 ****
> --- 236,245 ----
>        *Need all calls
>        */
>       public Method methodFromCall(CallT call){
> +         if (!call.getLangtype()) {
> +             System.out.println("Missing langtype attribute.");
> +             return null;
> +         }
>           if (call.getLangtype().equalsIgnoreCase("java")){
>               return methodFromCallJava(call);
>           } else if (call.getLangtype().equalsIgnoreCase("soapui")){
> ***************
> *** 244,250 ****
>               return methodFromCallTestGen(call);
>           } else
>               return methodFromCallScript(call);
> !         /*System.out.println("Unknow languaje type");
>           return null;*/
>       }
>
> --- 248,254 ----
>               return methodFromCallTestGen(call);
>           } else
>               return methodFromCallScript(call);
> !         /*System.out.println("Unknown language type");
>           return null;*/
>       }
>
> ***************
> *** 378,389 ****
>                   CallT otherCall = calls.get(i);
>                   if (otherCall.getName() != null &&
>                       otherCall.getName().equalsIgnoreCase 
> (call.getName()) &&
>                       otherCall.getLangtype().equalsIgnoreCase 
> (call.getLangtype())){
>                       return objects.get(i);
>                   }
>               }
>           }
> !         if (call.getLangtype().equalsIgnoreCase("soapui")){
>               return null;
>           } else if (call.getLangtype().equalsIgnoreCase("java")){
>               return objectFromCallJava(call);
> --- 382,397 ----
>                   CallT otherCall = calls.get(i);
>                   if (otherCall.getName() != null &&
>                       otherCall.getName().equalsIgnoreCase 
> (call.getName()) &&
> +                     otherCall.getLangtype() &&
>                       otherCall.getLangtype().equalsIgnoreCase 
> (call.getLangtype())){
>                       return objects.get(i);
>                   }
>               }
>           }
> !         if (!call.getLangtype()) {
> !             System.out.println("Missing langtype attribute.");
> !             return objectFromCallScript(call);
> !         } else if (call.getLangtype().equalsIgnoreCase("soapui")) {
>               return null;
>           } else if (call.getLangtype().equalsIgnoreCase("java")){
>               return objectFromCallJava(call);
> ***************
> *** 411,424 ****
>
>
>       public Object[] argumentsFromCall(CallT call){
> !         if (call.getLangtype().equalsIgnoreCase("soapui"))
>               return this.argumentsFromCallSoapui(call);
>           else if (call.getLangtype().equalsIgnoreCase("java")){
>               return this.argumentsFromCallJava 
> (Loader,call,dpls,actualMessageSize);
>           } else if (call.getLangtype().equalsIgnoreCase 
> ("TestGen4Web")){
>               return this.argumentsFromCallTestGen(call);
>           } else
> !             return argumentsFormCallScript 
> (call,dpls,actualMessageSize);
>       }
>
>
> --- 419,435 ----
>
>
>       public Object[] argumentsFromCall(CallT call){
> !
> !         if (!call.getLangtype()) {
> !             System.out.println("Missing langtype attribute.");
> !         } else if (call.getLangtype().equalsIgnoreCase("soapui"))
>               return this.argumentsFromCallSoapui(call);
>           else if (call.getLangtype().equalsIgnoreCase("java")){
>               return this.argumentsFromCallJava 
> (Loader,call,dpls,actualMessageSize);
>           } else if (call.getLangtype().equalsIgnoreCase 
> ("TestGen4Web")){
>               return this.argumentsFromCallTestGen(call);
>           } else
> !             return argumentsFromCallScript 
> (call,dpls,actualMessageSize);
>       }
>
>
> ***************
> *** 432,451 ****
>       private Object getScriptObject(CallT call){
>           for (CallT otherCall : scriptMap.keySet()){
>               if (otherCall.getName() != null &&
> !                     otherCall.getName().equalsIgnoreCase 
> (call.getName()) &&
> !                     otherCall.getLangtype().equalsIgnoreCase 
> (call.getLangtype())){
> !                     return scriptMap.get(otherCall);
> !                 }
>           }
>           return null;
>       }
>
>       /**
>        *Create the arguments from the script
> !      *Alos it create the engines
> !      *that is istored in my obj*/
>       Object myobj;
> !     public Object[] argumentsFormCallScript (CallT call,HashMap  
> dpls,int amz){
>           Object argsScript[];
>           ScriptEngine engine;
>           if ("jython".equalsIgnoreCase(call.getLangtype())){
> --- 443,462 ----
>       private Object getScriptObject(CallT call){
>           for (CallT otherCall : scriptMap.keySet()){
>               if (otherCall.getName() != null &&
> !                 otherCall.getName().equalsIgnoreCase(call.getName 
> ()) &&
> !                 call.getLangType() && otherCall.getLangtype() &&
> !                 otherCall.getLangtype().equalsIgnoreCase 
> (call.getLangtype())){
> !                 return scriptMap.get(otherCall);
> !             }
>           }
>           return null;
>       }
>
>       /**
>        *Create the arguments from the script
> !      *Also create the engines that are stored in my obj */
>       Object myobj;
> !     public Object[] argumentsFromCallScript (CallT call,HashMap  
> dpls,int amz){
>           Object argsScript[];
>           ScriptEngine engine;
>           if ("jython".equalsIgnoreCase(call.getLangtype())){
> ***************
> *** 483,489 ****
>               try {
>                   java.net.URL myfile = new java.net.URL(file);
>                   file = myfile.getPath();
> !             } catch (Exception e){}
>
>               java.io.FileReader f = new java.io.FileReader(file);
>
> --- 494,502 ----
>               try {
>                   java.net.URL myfile = new java.net.URL(file);
>                   file = myfile.getPath();
> !             } catch (Exception e){
> !                 e.printStackTrace();
> !             }
>
>               java.io.FileReader f = new java.io.FileReader(file);
>
> ***************
> *** 846,855 ****
>   	    return;
>   	//Not java not implemented
>   	String lang = call.getLangtype();
> ! 	if (lang.equalsIgnoreCase("java") &&
> ! 	    lang.equalsIgnoreCase("python")&&
> !             lang.equalsIgnoreCase("soapui") &&
> !             lang.equalsIgnoreCase("testgen4web"))
>   	    return ;
>   	if (lang.compareTo("python") == 0){
>               jythonCall(call);
> --- 859,871 ----
>   	    return;
>   	//Not java not implemented
>   	String lang = call.getLangtype();
> !        // This could never happen. Did he mean to put ! before  
> equals...()?
> !        // Maybe this was changed from compareTo to  
> equalsIgnoreCase, forgetting that
> !        // with the former, 0 means equal, and with the latter,  
> true means equal.
> ! 	if (!lang.equalsIgnoreCase("java") &&
> ! 	    !lang.equalsIgnoreCase("python")&&
> !             !lang.equalsIgnoreCase("soapui") &&
> !             !lang.equalsIgnoreCase("testgen4web"))
>   	    return ;
>   	if (lang.compareTo("python") == 0){
>               jythonCall(call);
> _______________________________________________
> Dev mailing list
> Dev at lists.pushtotest.com
> http://lists.pushtotest.com/mailman/listinfo/dev



--
Frank Cohen, PushToTest, http://www.PushToTest.com, phone 408 374 7426
TestMaker: The open-source SOA test automation tool





More information about the Dev mailing list