multiple instances of superclass member attributeNPE on constructor and superclassKotlin: Superclass is not accessible from traitMultiple variable let in KotlinSort collection by multiple fields in KotlinKotlin and generics, implementing abstract generic class with generic arrayExpecting member declaration in KotlinLazy initialization of nullable memberKotlin superClass KclassDagger2 generate multiple instancesKotlin reflection change instance and all members that use the instance
Why is the design of haulage companies so “special”?
Lied on resume at previous job
What does it exactly mean if a random variable follows a distribution
Information to fellow intern about hiring?
How would photo IDs work for shapeshifters?
What are the advantages and disadvantages of running one shots compared to campaigns?
Ideas for 3rd eye abilities
Why do we use polarized capacitors?
Landlord wants to switch my lease to a "Land contract" to "get back at the city"
Is there a way to make member function NOT callable from constructor?
Is this food a bread or a loaf?
Is there a familial term for apples and pears?
Are objects structures and/or vice versa?
Is Social Media Science Fiction?
What is the meaning of "of trouble" in the following sentence?
Was there ever an axiom rendered a theorem?
How to make payment on the internet without leaving a money trail?
How to answer pointed "are you quitting" questioning when I don't want them to suspect
Is it wise to focus on putting odd beats on left when playing double bass drums?
Prime joint compound before latex paint?
Where to refill my bottle in India?
Crop image to path created in TikZ?
When blogging recipes, how can I support both readers who want the narrative/journey and ones who want the printer-friendly recipe?
How could a lack of term limits lead to a "dictatorship?"
multiple instances of superclass member attribute
NPE on constructor and superclassKotlin: Superclass is not accessible from traitMultiple variable let in KotlinSort collection by multiple fields in KotlinKotlin and generics, implementing abstract generic class with generic arrayExpecting member declaration in KotlinLazy initialization of nullable memberKotlin superClass KclassDagger2 generate multiple instancesKotlin reflection change instance and all members that use the instance
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have an abstract stub class that needs to be subclasses to add spring annotations.
abstract class ConsumerStub<TYPE>
val receivedMessages: MutableMap<String, TYPE> = ConcurrentHashMap()
open fun processMessage(@Payload payload: TYPE, record: ConsumerRecord<String, *>)
this.receivedMessages[record.key()] = payload
fun receivedMessageWithKey(key: String): Boolean = this.receivedMessages.contains(key)
fun receivedMessageWithKeyCallable(key: String): Callable<Boolean> = Callable receivedMessageWithKey(key)
fun getReceiveMessageWithKey(key: String): TYPE? = this.receivedMessages[key]
fun reset()
this.receivedMessages.clear()
for example:
open class WorkflowRequestConsumerStub: ConsumerStub<InternalWorkflowRequest>()
@KafkaListener(
id = "xyzRequestConsumerStub",
topics = ["abc-workflow-requests"]
)
override fun processMessage(
@Payload payload: InternalWorkflowRequest,
record: ConsumerRecord<String, *>
)
super.processMessage(payload, record)
I am seeing some really weird behaviour with the receivedMessages.
After some debugging I realised there seem to be 2 instances of receivedMessages.
stub.reset() throws a null pointer exception
after changing the code to initialize receivedMessages in reset(), processMessage() and receivedMessageWithKey() are seeing 2 different receivedMessages with different objectIds.
what's going on? In java the subclass should have access to any protected members in the super, so I assume the same applies to kotlin.
UPDATE: this works as expected when defining receivedMessages abstract and override in the implementations. That really sucks if this is how it should be done in kotlin. In this case there is no need for the implementation to care about the map.
kotlin
add a comment |
I have an abstract stub class that needs to be subclasses to add spring annotations.
abstract class ConsumerStub<TYPE>
val receivedMessages: MutableMap<String, TYPE> = ConcurrentHashMap()
open fun processMessage(@Payload payload: TYPE, record: ConsumerRecord<String, *>)
this.receivedMessages[record.key()] = payload
fun receivedMessageWithKey(key: String): Boolean = this.receivedMessages.contains(key)
fun receivedMessageWithKeyCallable(key: String): Callable<Boolean> = Callable receivedMessageWithKey(key)
fun getReceiveMessageWithKey(key: String): TYPE? = this.receivedMessages[key]
fun reset()
this.receivedMessages.clear()
for example:
open class WorkflowRequestConsumerStub: ConsumerStub<InternalWorkflowRequest>()
@KafkaListener(
id = "xyzRequestConsumerStub",
topics = ["abc-workflow-requests"]
)
override fun processMessage(
@Payload payload: InternalWorkflowRequest,
record: ConsumerRecord<String, *>
)
super.processMessage(payload, record)
I am seeing some really weird behaviour with the receivedMessages.
After some debugging I realised there seem to be 2 instances of receivedMessages.
stub.reset() throws a null pointer exception
after changing the code to initialize receivedMessages in reset(), processMessage() and receivedMessageWithKey() are seeing 2 different receivedMessages with different objectIds.
what's going on? In java the subclass should have access to any protected members in the super, so I assume the same applies to kotlin.
UPDATE: this works as expected when defining receivedMessages abstract and override in the implementations. That really sucks if this is how it should be done in kotlin. In this case there is no need for the implementation to care about the map.
kotlin
If you're seeing 2 different instances ofreceivedMessages
that most likely means that you have 2 different instances of aConsumerStub
subclass.
– Erwin Bolwidt
Mar 22 at 3:37
In that case they should be both initialised to concurrenthashmap. In some cases it's null. Unless spring is doing some reflection magic with the bean
– miklesw
Mar 22 at 3:40
Nothing in the code you show should lead to such problems. Try creating a Minimal, Complete, and Verifiable example (stackoverflow.com/help/mcve).
– Alexey Romanov
Mar 22 at 7:44
could be an issue of how kotlin generated binaries work with spring proxying. This kind of setup works fine in java+spring. using an abstract receivedMessages solved the problem. but it's a bad solution
– miklesw
Mar 22 at 8:35
add a comment |
I have an abstract stub class that needs to be subclasses to add spring annotations.
abstract class ConsumerStub<TYPE>
val receivedMessages: MutableMap<String, TYPE> = ConcurrentHashMap()
open fun processMessage(@Payload payload: TYPE, record: ConsumerRecord<String, *>)
this.receivedMessages[record.key()] = payload
fun receivedMessageWithKey(key: String): Boolean = this.receivedMessages.contains(key)
fun receivedMessageWithKeyCallable(key: String): Callable<Boolean> = Callable receivedMessageWithKey(key)
fun getReceiveMessageWithKey(key: String): TYPE? = this.receivedMessages[key]
fun reset()
this.receivedMessages.clear()
for example:
open class WorkflowRequestConsumerStub: ConsumerStub<InternalWorkflowRequest>()
@KafkaListener(
id = "xyzRequestConsumerStub",
topics = ["abc-workflow-requests"]
)
override fun processMessage(
@Payload payload: InternalWorkflowRequest,
record: ConsumerRecord<String, *>
)
super.processMessage(payload, record)
I am seeing some really weird behaviour with the receivedMessages.
After some debugging I realised there seem to be 2 instances of receivedMessages.
stub.reset() throws a null pointer exception
after changing the code to initialize receivedMessages in reset(), processMessage() and receivedMessageWithKey() are seeing 2 different receivedMessages with different objectIds.
what's going on? In java the subclass should have access to any protected members in the super, so I assume the same applies to kotlin.
UPDATE: this works as expected when defining receivedMessages abstract and override in the implementations. That really sucks if this is how it should be done in kotlin. In this case there is no need for the implementation to care about the map.
kotlin
I have an abstract stub class that needs to be subclasses to add spring annotations.
abstract class ConsumerStub<TYPE>
val receivedMessages: MutableMap<String, TYPE> = ConcurrentHashMap()
open fun processMessage(@Payload payload: TYPE, record: ConsumerRecord<String, *>)
this.receivedMessages[record.key()] = payload
fun receivedMessageWithKey(key: String): Boolean = this.receivedMessages.contains(key)
fun receivedMessageWithKeyCallable(key: String): Callable<Boolean> = Callable receivedMessageWithKey(key)
fun getReceiveMessageWithKey(key: String): TYPE? = this.receivedMessages[key]
fun reset()
this.receivedMessages.clear()
for example:
open class WorkflowRequestConsumerStub: ConsumerStub<InternalWorkflowRequest>()
@KafkaListener(
id = "xyzRequestConsumerStub",
topics = ["abc-workflow-requests"]
)
override fun processMessage(
@Payload payload: InternalWorkflowRequest,
record: ConsumerRecord<String, *>
)
super.processMessage(payload, record)
I am seeing some really weird behaviour with the receivedMessages.
After some debugging I realised there seem to be 2 instances of receivedMessages.
stub.reset() throws a null pointer exception
after changing the code to initialize receivedMessages in reset(), processMessage() and receivedMessageWithKey() are seeing 2 different receivedMessages with different objectIds.
what's going on? In java the subclass should have access to any protected members in the super, so I assume the same applies to kotlin.
UPDATE: this works as expected when defining receivedMessages abstract and override in the implementations. That really sucks if this is how it should be done in kotlin. In this case there is no need for the implementation to care about the map.
kotlin
kotlin
edited Mar 22 at 6:40
miklesw
asked Mar 22 at 1:45
mikleswmiklesw
234416
234416
If you're seeing 2 different instances ofreceivedMessages
that most likely means that you have 2 different instances of aConsumerStub
subclass.
– Erwin Bolwidt
Mar 22 at 3:37
In that case they should be both initialised to concurrenthashmap. In some cases it's null. Unless spring is doing some reflection magic with the bean
– miklesw
Mar 22 at 3:40
Nothing in the code you show should lead to such problems. Try creating a Minimal, Complete, and Verifiable example (stackoverflow.com/help/mcve).
– Alexey Romanov
Mar 22 at 7:44
could be an issue of how kotlin generated binaries work with spring proxying. This kind of setup works fine in java+spring. using an abstract receivedMessages solved the problem. but it's a bad solution
– miklesw
Mar 22 at 8:35
add a comment |
If you're seeing 2 different instances ofreceivedMessages
that most likely means that you have 2 different instances of aConsumerStub
subclass.
– Erwin Bolwidt
Mar 22 at 3:37
In that case they should be both initialised to concurrenthashmap. In some cases it's null. Unless spring is doing some reflection magic with the bean
– miklesw
Mar 22 at 3:40
Nothing in the code you show should lead to such problems. Try creating a Minimal, Complete, and Verifiable example (stackoverflow.com/help/mcve).
– Alexey Romanov
Mar 22 at 7:44
could be an issue of how kotlin generated binaries work with spring proxying. This kind of setup works fine in java+spring. using an abstract receivedMessages solved the problem. but it's a bad solution
– miklesw
Mar 22 at 8:35
If you're seeing 2 different instances of
receivedMessages
that most likely means that you have 2 different instances of a ConsumerStub
subclass.– Erwin Bolwidt
Mar 22 at 3:37
If you're seeing 2 different instances of
receivedMessages
that most likely means that you have 2 different instances of a ConsumerStub
subclass.– Erwin Bolwidt
Mar 22 at 3:37
In that case they should be both initialised to concurrenthashmap. In some cases it's null. Unless spring is doing some reflection magic with the bean
– miklesw
Mar 22 at 3:40
In that case they should be both initialised to concurrenthashmap. In some cases it's null. Unless spring is doing some reflection magic with the bean
– miklesw
Mar 22 at 3:40
Nothing in the code you show should lead to such problems. Try creating a Minimal, Complete, and Verifiable example (stackoverflow.com/help/mcve).
– Alexey Romanov
Mar 22 at 7:44
Nothing in the code you show should lead to such problems. Try creating a Minimal, Complete, and Verifiable example (stackoverflow.com/help/mcve).
– Alexey Romanov
Mar 22 at 7:44
could be an issue of how kotlin generated binaries work with spring proxying. This kind of setup works fine in java+spring. using an abstract receivedMessages solved the problem. but it's a bad solution
– miklesw
Mar 22 at 8:35
could be an issue of how kotlin generated binaries work with spring proxying. This kind of setup works fine in java+spring. using an abstract receivedMessages solved the problem. but it's a bad solution
– miklesw
Mar 22 at 8:35
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55291726%2fmultiple-instances-of-superclass-member-attribute%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55291726%2fmultiple-instances-of-superclass-member-attribute%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If you're seeing 2 different instances of
receivedMessages
that most likely means that you have 2 different instances of aConsumerStub
subclass.– Erwin Bolwidt
Mar 22 at 3:37
In that case they should be both initialised to concurrenthashmap. In some cases it's null. Unless spring is doing some reflection magic with the bean
– miklesw
Mar 22 at 3:40
Nothing in the code you show should lead to such problems. Try creating a Minimal, Complete, and Verifiable example (stackoverflow.com/help/mcve).
– Alexey Romanov
Mar 22 at 7:44
could be an issue of how kotlin generated binaries work with spring proxying. This kind of setup works fine in java+spring. using an abstract receivedMessages solved the problem. but it's a bad solution
– miklesw
Mar 22 at 8:35