question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extending AbstractThrowableProblem not working as expected in Kotlin

See original GitHub issue

When extending AbstractThrowableProblem in Java it works as expected. Extending the class in Kotlin leads to a compile error:

Class 'MyProblem' is not abstract and does not implement abstract base class member public abstract fun getCause(): Exceptional! defined in org.zalando.problem.AbstractThrowableProblem

Description

Working Java Problem:

public class MyProblemJava extends AbstractThrowableProblem {

    public MyProblemJava(String message) {
        super(URI.create("https://www.google.de"), "My Problem", Status.BAD_REQUEST, message);
    }
}

The same problem converted to Kotlin

import org.zalando.problem.AbstractThrowableProblem
import org.zalando.problem.Status.BAD_REQUEST
import java.net.URI

class MyProblem(message: String?) : AbstractThrowableProblem(TYPE, "My Problem", BAD_REQUEST, message) {

    companion object {
        val TYPE = URI.create("https://www.google.de/workflow-problem")
    }
}

Expected Behavior

MyProblem should not have to override getCause() as the Java class does not have to do, either.

Actual Behavior

Compilation issue.

Your Environment

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
whiskeysierracommented, Oct 22, 2019

as AbstractThrowableProblem doesn’t override the getCause method

It inherits it from ThrowableProblem. There is no reason to implement it again:

https://github.com/zalando/problem/blob/21e28bcfbdb3984d0f26a2a44b729b88ddb5f709/problem/src/main/java/org/zalando/problem/ThrowableProblem.java#L38-L42

I have no idea if this is a Kotlin issue

Since it works in Java I’m inclined to say yes.

0reactions
jehrenzweig-leagueappscommented, May 2, 2022

Looks like the issue that @unlimitedsola reported, wrt the IR backend (https://youtrack.jetbrains.com/issue/KT-45853), is fixed.

This comment was posted with regards to the need to redundantly override getCause() with the same implementation as the superclass (i.e. super.getCause()):

Hi , you are right. This is caused by "Inconsistent override tree when Kotlin property accessor is 
covariantly overridden by a Java method" (https://youtrack.jetbrains.com/issue/KT-46042), 
which, unfortunately, we can't fix right away without deprecation cycle.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Customise and remove unrequired fields from Zalando ...
I customized the response body by extending from AbstractThrowableProblem by invoking the super constructor and passing the required fields.
Read more >
A Guide to the Problem Spring Web Library - Baeldung
Learn how to use the Problem Spring Web library to create messages with the ... We just need to extend the AbstractThrowableProblem class:...
Read more >
kotlin extend abstract class - Seni.co.id
Word for someone who looks for problems and raises the alarm about them, Simple op-amp comparator circuit not behaving as expected. Sebuah abstract...
Read more >
Kotlin Language Documentation 1.7.21
Learn Kotlin fundamentals. Install Kotlin. Create your powerful application with Kotlin. Is anything missing? Kotlin Multiplatform. Kotlin ...
Read more >
AbstractThrowableProblem (Problem 0.20.3 API) - javadoc.io
@API(status=STABLE) @Immutable public abstract class AbstractThrowableProblem extends ThrowableProblem. See Also: Serialized Form ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found