[classad-users] RecordExpr manipulation


Date: Mon, 11 Nov 2002 11:02:57 -0600 (CST)
From: Alessandro Maraschini <alessandro.maraschini@xxxxxxxxxx>
Subject: [classad-users] RecordExpr manipulation
Hi all,
Once upon a time ( 2002, Agoust , 7th) I wrote you  about a lack
of RecordExpr, this was your answer:
 
 
=======================================================================
Subject:
       Re: [classad-users]
how to remove an attribute
   Date:
       Wed, 07 Aug 2002
20:10:45 -0500
  From:
       Alain Aslag Roy
<roy@xxxxxxxxxxx>
    To:
       classad-users@xxxxxxxxxxx
    CC:
       Alessandro Maraschini
<alessandro.maraschini@xxxxxxxxxx>
>I'm working with the Java classAd Package and I'm wondering how to
remove
>an inserted attribute from a RecordExpr instance.
>I was expected to find something like the
>bool ClassAd::Delete( const string &attrName )
>method which I had used with the C++ library but I didn't.
It should exist, but it doesn't. You can get the Java source code from
the
ClassAd web page--feel free to write a version of it!
-alain
========================================================================
 
 
 
Well, I try to implement that method and it seemed to work quite well
so far.
However today I realized that the supposed case-insensitive behaviour
doesn't work well.
I tried to dig a bit deeper into your code but I would like you to
investigate over this problem if possible.
 
 
These are the methods added in RecordExpr.java file:
public RecordExpr removeAttribute(String name) {
      return removeAttribute(CiString.getInstance(name));
}
public RecordExpr insertAttribute(CiString key, Expr expr) {
        if (key == null) {
           
throw new IllegalArgumentException(
                       
"null attribute name " + key);
        }
        if (expr == null) {
           
throw new IllegalArgumentException(
                       
"null value for attribute " + key);
        }
        if (!map.containsKey(key))
           
attrNames.add(key.toString());
        map.put(key, expr);
        return this;
}
 
And here follows three simple tests:
RecordExpr re = new RecordExpr() ;
String upAttr = "Attribute" ;
String lowAttr = "attribute" ;
 
 
 1)  when the case of the attributes inserted/removed is exactly
the same there is no problem:
    re.insertAttribute( upAttr , (Expr) Constant.getInstance(
5 )   );
    System.out.println( "put upper case: " + re) ;
    re.removeAttribute( upAttr ) ;
    System.out.println( "removed:" + re) ;
 the output is:
put upper case: [ Attribute = 5 ]
removed:[  ]
2) when I remove an attribute with a different case of the inserted
one a  java.lang.NullPointerException is thrown by the toString method:
re.insertAttribute( lowAttr , (Expr) Constant.getInstance( 5 ) 
);
System.out.println( "put lower case: " + re) ;
re.removeAttribute( upAttr) ;
System.out.println( "removed: "+re );
the output is:
put lower case: [ attribute = 5 ]
Exception in thread "main" java.lang.NullPointerException
        at condor.classad.RecordExpr.toString(RecordExpr.java:308)
        at java.lang.String.valueOf(String.java:2173)
        at java.lang.StringBuffer.append(StringBuffer.java:369)
        at Main.<init>(Main.java:121)
        at Main.main(Main.java:400)
3) The second point leads the RecordExpr instance to an unpredictable
instable situation that allows to create "impossible classAd":
    re.insertAttribute( lowAttr , (Expr) Constant.getInstance(
6 )  );
    System.out.println( "put lower case:" + re) ;
    re.removeAttribute( upAttr) ;
    re.insertAttribute( lowAttr , (Expr)  Constant.getInstance(
7 )  );
    System.out.println( "put again upper case : " +
re) ;
 
the output is:
put lower case: [ attribute = 6 ]
put again upper case : [ attribute = 7; attribute = 7 ]
 
 
 
 
 
-- 
=============================================================
Alessandro Maraschini
GRID R&D Group
Defence, Space & Environment Division
DATAMAT S.p.A.
Via Laurentina, 760 -I- 00143 Rome - Italy
http://www.datamat.it
mailto:alessandro.maraschini@xxxxxxxxxx
Phone: +39 06 5027 4501 (direct) +39 06 5027 4570 (secretary)
Fax: +39 06 5027 4500
=============================================================
 


[← Prev in Thread] Current Thread [Next in Thread→]
  • [classad-users] RecordExpr manipulation, Alessandro Maraschini <=