xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andreas Hartmann <andr...@apache.org>
Subject Re: Handling null parameters in ParsedURLProtocolHandler.parseURL(String)
Date Tue, 27 Nov 2007 09:27:28 GMT
Hi Cameron,

thanks for your comments!

Cameron McCormack schrieb:

[...]

>> in Lenya, we'd like to use a Cocoon component (SVGSerializer) which 
>> depends on Batik 1.6. If we enable the SourceProtocolHandler (a 
>> Cocoon-specific implementation of ParsedURLProtocolHandler), we're 
>> getting an NPE when the urlStr parameter is null:
>>
>>   https://issues.apache.org/jira/browse/COCOON-2148
>>
>> Should the ParsedURLProtocolHandler be aware of the circumstance that 
>> urlStr can be null? Or is this an error case?
> 
> As pointed out in the above Cocoon bug, the
> ParsedURLDefaultProtocolHandler does explicitly check for a null urlStr.
> ParsedURLDataProtocolHandler, on the other hand, doesn’t.
> 
> ParsedURLDefaultProtocolHandler just returns an uninitialised
> ParsedURLData object when parseURL(null) is called.  I don’t know if
> passing null to parseURL makes much sense, though.  What is it used for
> in Cocoon?

I guess an important point is that Cocoon's SourceProtocolHandler is 
registered for the "null protocol", i.e. it feels reponsible for all 
URLs. Maybe this is was not considered when the API was designed and is 
therefore discouraged?

I'll try to describe what happens:

The Cocoon SVGSerializer calls the tanscoder on a TranscoderInput object 
which was created from a DOM document:

   TranscoderInput transInput = new TranscoderInput(doc);
   TranscoderOutput transOutput = new TranscoderOutput(this.output);
   transcoder.transcode(transInput, transOutput);

Note that the URI field of the transInput object isn't set (I don't know 
if this is mandatory).

The null parameter occurs because the SVGAbstractTranscoder creates a 
ParsedURL object with the TranscoderInput URI field:

XMLAbstractTranscoder:

   75:  String uri = input.getURI();
  142:  transcode(document, uri, output);

SVGAbstractTranscoder:

  243:  String ref = new ParsedURL(uri).getRef();   => NPE

The XMLAbstractTranscoder is apparently aware that uri can be null. So I 
guess that the ParsedURLProtocolHandler should also be prepared to 
handle null values. Or Cocoon should reconsider the registration of the 
SourceProtocolHandler for the "null protocol". WDYT?

Thanks again!

-- Andreas


-- 
Andreas Hartmann, CTO
BeCompany GmbH
http://www.becompany.ch
Tel.: +41 (0) 43 818 57 01


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Mime
View raw message