-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Casl 534 java proxy fix #347
Conversation
Signed-off-by: Jakub Amanowicz <[email protected]>
0fc834a
to
cbac9ee
Compare
val constructor: KFunction<T> = primaryNonArgConstructorOf(klass) | ||
?: firstNonArgConstructorOf(klass) | ||
?: throw IllegalArgumentException("Unable to find primary or non-arg constructor for class: ${klass.qualifiedName}") | ||
proxy = constructor.call() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, any constructor that does not require arguments is fine for us, we should always first try the primary constructor, but if that does not match, try to find any other constructor.
These checks and searching for the correct constructor can be time consuming, I would suggest to add a cache here, a concurrent hash-map, to cache the found constructors. Like:
var constructor = cache[klass]
if (constructor == null) {
constructor = ... find the correct one
cache[klass] = constructor
}
We do not need any synchronization here, because we can assume that the finding operation is idempotent, so even when multiple threads in parallel enter the search and override each other, the cache should work after that as intended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Signed-off-by: Jakub Amanowicz <[email protected]>
Signed-off-by: Jakub Amanowicz <[email protected]>
@@ -512,11 +512,21 @@ actual class Platform { | |||
if (klass.isInstance(proxy)) return proxy as T | |||
if (doNotOverride) throw IllegalStateException("The symbol $symbol is already bound to incompatible type") | |||
} | |||
proxy = klass.primaryConstructor!!.call() | |||
|
|||
proxy = nonArgConstructorFor(klass).call() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the caching, should be just a few code lines, but avoids to always go through reflection and search through constructor lists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Signed-off-by: Jakub Amanowicz <[email protected]>
No description provided.