DJVM and reflection
I strongly suspect we can do something about reflection, it's just not been a priority so far. The SecurityManager architecture supports controlling reflection and the DJVM already loads into its own classloader. Determinism will be opt-in anyway, so it may be that it's rolled out in phases.
|
|
Roman Plášil
I didn't test it on latest so it's possible. The version I used is with corda 4.1, commit c11f6c15f7
Kinda bummed about no reflection then. Anyone else here has views? Do you write contracts fully manually and then hold fingers crossed? |
|
Chris Rankin
Hi Roman,
There are currently no plans to create "safe" Java reflection inside the DJVM, but I am concerned that you are seeing errors with SomeState::class. The latest version of the DJVM code (from the https://github.com/corda/djvm repository) does execute this test successfully:
@Test
Are you using an old version of the DJVM, please? What kind of error are you seeing?fun `test kotlin class access`() = parentedSandbox { val executor = TaskExecutor(classLoader) val accessTask = executor.toSandboxClass(AccessKotlinClass::class.java).newInstance() assertThat(executor.execute(accessTask, "Message")).isEqualTo(executor.toSandboxClass(String::class.java)) assertThat(executor.execute(accessTask, 0L)).isEqualTo(executor.toSandboxClass(Long::class.javaObjectType)) assertThat(executor.execute(accessTask, null)).isEqualTo(executor.toSandboxClass(Henry::class.java)) } class AccessKotlinClass : Function<Any?, Class<*>> { override fun apply(input: Any?): Class<*> { return if (input == null) { Henry::class.java } else { input::class.java } } } class Henry Cheers, Chris
From: corda-dev@groups.io <corda-dev@groups.io> on behalf of Roman Plášil via Groups.Io <quiark@...>
Sent: 05 August 2019 06:40:54 To: corda-dev@groups.io <corda-dev@groups.io> Subject: [corda-dev] DJVM and reflection Hi,
I would like to ask whether we can reasonably expect to have basic reflection available for contract code when DJVM becomes required. I understand when left unchecked, reflection could bypass any security checks but on the other hand, I guess we are not the only ones currently using it. It is mostly for the purpose of ensuring that equality of all properties is checked during state evolution. So getting a list of properties (possibly even inherited ones) as well as being able to invoke a property reference would be needed. (I know about the trick with .copy() but it is simply not flexible enough) I tried with the current DJVM tool and get blocked as soon as using SomeState::class which we also use to construct exception message in some helper functions. If this is not possible, I also thought about some code generation / macros for contracts, is anyone going in this direction?
Roman Plášil | Principal Engineer CryptoBLK Limited I Revolutionize IT with Cryptography and Blockchain |
|
Roman Plášil
Hi,
I would like to ask whether we can reasonably expect to have basic reflection available for contract code when DJVM becomes required. I understand when left unchecked, reflection could bypass any security checks but on the other hand, I guess we are not the only ones currently using it. It is mostly for the purpose of ensuring that equality of all properties is checked during state evolution. So getting a list of properties (possibly even inherited ones) as well as being able to invoke a property reference would be needed. (I know about the trick with .copy() but it is simply not flexible enough) I tried with the current DJVM tool and get blocked as soon as using SomeState::class which we also use to construct exception message in some helper functions. If this is not possible, I also thought about some code generation / macros for contracts, is anyone going in this direction?
Roman Plášil | Principal Engineer CryptoBLK Limited I Revolutionize IT with Cryptography and Blockchain |
|