This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

What is the use of (require <xyz>) and explicit type declarations?


Hi,

What is the use of a require "statement" w.r.t. file-compilation?

I get the exact same warnings whether (require ...KeyStore> is present or not.

;;(require <java.security.KeyStore>)
(define keystore ;;:: <java.security.KeyStore>
  (invoke-static <java.security.KeyStore> 'getInstance "JKS"))
(invoke keystore 'load
	(make <java.io.FileInputStream> "Keys.jks")
	thepasswd)
(define thepubcert ;;:: <java.security.cert.X509Certificate>
  (invoke keystore 'getCertificate "A"))

re-sign.scm:66:2: warning - no method `load' in java.lang.Object
re-sign.scm:74:4: warning - no method `getCertificate' in java.lang.Object


Furthermore, why does there seem to be a need for top-level type declarations (still in the context of file-compilation)?
I thought that the compiler had enough information from the code and was using
reflection abilities (e.g. obtaining the result type from 'getinstance) to
infer the resulting type of keystore?

To get rid of the warnings one has to use:
(define keystore :: <java.security.KeyStore> ; needed
  ...)

Is this a symptom of the type inference engine of which Per recently said that it's not as good as he wishes for?

Similarly for embedded calls, e.g.
(define (get-subject-name keyinfo :: <org.apache.xml.security.keys.KeyInfo>)
  (and
   (invoke keyinfo 'containsX509Data)
   (let ((x509-data (invoke keyinfo 'itemX509Data 0)))
     (and
      (invoke x509-data 'containsSubjectName)
      (invoke (invoke x509-data 'itemSubjectName 0)
	      'getSubjectName)))))
re-sign.scm:248:6: warning - no method `containsSubjectName' in java.lang.Object
re-sign.scm:250:8: warning - no method `getSubjectName' in java.lang.Object
re-sign.scm:250:16: warning - no method `itemSubjectName' in java.lang.Object
note no warning for containsX509Data because the type of 'keyinfo' is explicit.


Similarly, what is the recommended way of avoiding warnings in conjunction
with nested calls, e.g.

(define (re-sign doc :: <org.w3c.dom.Document> subject-name privkey)
  ;; Using inner define instead of let because of
  ;; superior interactive RAD & testing
  (define oldsigelem (select-single-node doc
		      "Signature" "http://www.w3.org/2000/09/xmldsig#";))
    ...
    (invoke (invoke oldsigelem 'getParentNode)
	    'replaceChild sigelem oldsigelem)
    ...)
re-sign.scm:213:6: warning - no method `replaceChild' in java.lang.Object
re-sign.scm:213:14: warning - no method `getParentNode' in java.lang.Object

I believe the compiler should know the return type of
(invoke oldsigelem 'getParentNode), shouldn't it?

I explicitly defined the return type of select-single-node:
(define (select-single-node (doc :: <org.w3c.dom.Document>)
			    (name :: <string>)
			    #!optional (namespace #f))
  <org.w3c.dom.Node>
  (let ((nodes :: <org.w3c.dom.NodeList> ...))
    ...))
Must I really add a (IMHO redundant) type declaration to oldsigelem?
(select-single-node is defined in the file prior to re-sign).

BTW, would you prefer full code so as to be able to execute it from my e-mails?

Thanks for your help,
       Jorg Hohle
Using kawa-1.7.jar


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]