You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Henrik Ståhl <He...@iconmedialab.se> on 2001/05/08 07:53:55 UTC

Thread sync issue in validation code?

When turning on validation in Xerces 1.3.1, the API
prints out error messages stating for example that
"validator for e-dtype not found" (approx). This only
happens if I call the parser from several concurrent
threads for some time and appears intermittently.
The attached example document and DTD will cause
this behaviour.

Can anyone tell me if this there is something wrong
with the XML code and/or DTD, or if it is a bug as
I assume? I can send the Java code I use to anyone
who wants to help, just let me know.

Thanks!

Henrik Ståhl
System Developer
Icon Medialab

test.dtd: 
=== 
<?xml version='1.0' encoding='UTF-8' ?> 
<!ELEMENT ROOTID (OrderNumber, User)> 
<!ATTLIST ROOTID ProcessCode (BuyOrder) #REQUIRED > 
<!ELEMENT OrderNumber (#PCDATA)> 
<!ATTLIST OrderNumber e-dtype NMTOKEN  #FIXED 'NMTOKEN' > 
<!ELEMENT User (#PCDATA)> 

test.xml 
=== 
<?xml version="1.0"?> 
<!DOCTYPE ROOTID SYSTEM "file:///dtd/test.dtd"> 
<ROOTID ProcessCode="BuyOrder"> 
        <OrderNumber>QWE123123</OrderNumber> 
        <User>ABC123</User> 
</ROOTID > 

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Thread sync issue in validation code?

Posted by Andy Clark <an...@apache.org>.
Elena Litani wrote:
> As far as I remember, the fix for the thread safety (with datatype
> registry) was introduced back in November. Am I right, Jeffrey?
> Henrik, I've looked at your bug report, but I could not reproduce the
> problem. I'll take a closer look at the code..

Last time I ran into these types of issues, I just did a
search over the entire source code tree looking for the
word "static". Then I checked every read/write access to
static variables to make sure that the access was
synchronized if the object was not initialized at static
constructor time (when the class is loaded). 

The Class object is a good object to use as the lock
when dealing with static objects. For example: 

  synchronized (MyObject.class) {
    // stuff
  }

The only downside is that the Java compiler turns the
"MyObject.class" into the following code in the bytecode:

  Class cls = Class.forName("MyObject");
  synchronized (cls) {
    // stuff
  }

which in turn signals a warning from a pure Java checker
because you are loading a class dynamically. Unless the
pure Java check is smart enough to know that this method
is being called with a static string and not from a 
string reference that could change (thus being dynamic).
Sadly, last time I used the checker software, it wasn't
that smart...

If you care about avoiding this, then just create a
static final lock object reference to be used. For
example:

  private static final Object LOCK = new Object();

  synchronized (LOCK) {
    // stuff
  }

-- 
Andy Clark * IBM, TRL - Japan * andyc@apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Thread sync issue in validation code?

Posted by Paul Jakubik <pa...@yahoo.com>.
You may already be aware of all these issues, but you
might find this article
(http://www.primenet.com/~jakubik/mpsafe/MultithreadSafety.pdf)
useful since it presents a checklist of ways that code
typically introduces thread safety issues (the
articles calls this ways that sharing is introduced).

I just thought it might help,

--Paul

--- Elena Litani <li...@ca.ibm.com> wrote:
> 
> Andy Clark wrote:
> > 
> > Henrik St�hl wrote:
> > > When turning on validation in Xerces 1.3.1, the
> API
> > > prints out error messages stating for example
> that
> > > "validator for e-dtype not found" (approx). This
> only
> > > happens if I call the parser from several
> concurrent
> > > threads for some time and appears
> intermittently.
> > 
> > Sounds like there is a static pool of datatype
> validators with
> > lazy object creation that doesn't synchronize
> access to it.
> > Elena: can you verify?
>  
> As far as I remember, the fix for the thread safety
> (with datatype
> registry) was introduced back in November. Am I
> right, Jeffrey?
> Henrik, I've looked at your bug report, but I could
> not reproduce the
> problem. I'll take a closer look at the code..
> 
> Elena
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail:
> xerces-j-user-help@xml.apache.org
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Serialization problems

Posted by Julian Reschke <ju...@gmx.de>.
Hi,

I'm trying to serialize a document that has been built using the DOM-Level-2
namespace aware methods:

  public static void main(String[] args)
    throws java.io.IOException {
    main main1 = new main();

    Document doc = new org.apache.xerces.dom.DocumentImpl ();

    Element root = doc.createElementNS ("ns1", "bar");
    doc.appendChild (root);
    root.setAttributeNS ("ns2", "attr", "val");

    org.apache.xml.serialize.OutputFormat of =
      new org.apache.xml.serialize.OutputFormat (doc, null, true);
    java.io.StringWriter out = new java.io.StringWriter();

    org.apache.xml.serialize.XMLSerializer ser =
      new org.apache.xml.serialize.XMLSerializer(out, of);

    ser.serialize (doc);

    System.out.println (out.toString());
  }

The result is:

<?xml version="1.0" ?>
<bar attr="val"/>

However, this is clearly wrong, it should be something like:

<?xml version="1.0" ?>
<bar xmlns="ns1" prefix:attr="val" xmlns:prefix="ns2" />

I reported the problem three months ago, but received no feedback:
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=596>.

Is there something wrong with my code, or does the serializer indeed not
able to serialize namespace declarations properly? I find this surprising
because the changelog for XMLSerializer.java shows that there have been
fixes applied regarding namespace handling.

Any feedback appreciated,

Julian


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Thread sync issue in validation code?

Posted by Elena Litani <li...@ca.ibm.com>.
Andy Clark wrote:
> 
> Henrik Ståhl wrote:
> > When turning on validation in Xerces 1.3.1, the API
> > prints out error messages stating for example that
> > "validator for e-dtype not found" (approx). This only
> > happens if I call the parser from several concurrent
> > threads for some time and appears intermittently.
> 
> Sounds like there is a static pool of datatype validators with
> lazy object creation that doesn't synchronize access to it.
> Elena: can you verify?
 
As far as I remember, the fix for the thread safety (with datatype
registry) was introduced back in November. Am I right, Jeffrey?
Henrik, I've looked at your bug report, but I could not reproduce the
problem. I'll take a closer look at the code..

Elena

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Thread sync issue in validation code?

Posted by Andy Clark <an...@apache.org>.
Henrik Ståhl wrote:
> When turning on validation in Xerces 1.3.1, the API
> prints out error messages stating for example that
> "validator for e-dtype not found" (approx). This only
> happens if I call the parser from several concurrent
> threads for some time and appears intermittently.

Sounds like there is a static pool of datatype validators with
lazy object creation that doesn't synchronize access to it.
Elena: can you verify?

-- 
Andy Clark * IBM, TRL - Japan * andyc@apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org