Back
list-model (clj)
(source)function
(list-model provider)
Examples
clojure
(ns clojure.test-clojure.java-interop
(:use clojure.test)
(:require [clojure.data :as data]
[clojure.inspector]
[clojure.pprint :as pp]
[clojure.set :as set]
[clojure.test-clojure.proxy.examples :as proxy-examples])
(:import java.util.Base64
(java.util.concurrent.atomic AtomicLong AtomicInteger)))
;; serialized-proxy can be regenerated using a modified version of
;; Clojure with the proxy serialization prohibition disabled and the
;; following code:
;; revert 271674c9b484d798484d134a5ac40a6df15d3ac3 to allow serialization
(comment
(require 'clojure.inspector)
(let [baos (java.io.ByteArrayOutputStream.)]
(with-open [baos baos]
(.writeObject (java.io.ObjectOutputStream. baos) (clojure.inspector/list-model nil)))
(prn (vector (System/getProperty "java.specification.version")
(.encodeToString (java.util.Base64/getEncoder) (.toByteArray baos))))))
(deftest test-proxy-non-serializable
(testing "That proxy classes refuse serialization and deserialization"
;; Serializable listed directly in interface list:
(is (thrown? java.io.NotSerializableException
(-> (java.io.ByteArrayOutputStream.)
(java.io.ObjectOutputStream.)
(.writeObject (proxy [Object java.io.Serializable] [])))))
;; Serializable included via inheritence:
(is (thrown? java.io.NotSerializableException
(-> (java.io.ByteArrayOutputStream.)
(java.io.ObjectOutputStream.)
(.writeObject (clojure.inspector/list-model nil)))))
;; Deserialization also prohibited:
(let [java-version (System/getProperty "java.specification.version")
serialized-proxy (get serialized-proxies java-version)]
(if serialized-proxy
(is (thrown? java.io.NotSerializableException
(-> serialized-proxy
decode-base64
java.io.ByteArrayInputStream. java.io.ObjectInputStream.
.readObject)))
(println "WARNING: Missing serialized proxy for Java" java-version "in test/clojure/test_clojure/java_interop.clj")))))