Question

Please help me to solve the ambiguous call in this code.

fac.newtransform() and fac.new signedinfo() is giving error saying:

reference to newTransform is ambiguous, both method newTransform(String,TransformParameterSpec) in XMLSignatureFactory and method newTransform(String,XMLStructure) in XMLSignatureFactory match

How can I call the actual function in XMLSignatureFactory?

   XMLSignatureFactory fac =XMLSignatureFactory.getInstance("DOM",
                (Provider) Class.forName(providerName).newInstance());

   Reference ref =fac.newReference("",fac.newDigestMethod(DigestMethod.SHA1, null),
    Collections.singletonList(fac.newTransform(Transform.ENVELOPED, null)),null, null);


   SignedInfo si = fac.newSignedInfo
       (fac.newCanonicalizationMethod
         (CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS, 
             null), 
        fac.newSignatureMethod(SignatureMethod.DSA_SHA1, 
            null),
        Collections.singletonList(ref));
Was it helpful?

Solution

You must cast the second argument:

newTransform("foo", (XMLStructure) null)

You are getting the ambiguous warning because null is a valid argument to both methods. You need to add the (XMLStructure) cast to tell the compiler the type of the object you are setting to null..

OTHER TIPS

newTransform(Transform.ENVELOPED, null);

This call is ambiguous because null will match both the method signatures newTransform(java.lang.String algorithm, XMLStructure params) and newTransform(java.lang.String algorithm, TransformParameterSpec params). Cast the null :

newTransform("foo", (XMLStructure) null)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top