Extending AbstractThrowableProblem not working as expected in Kotlin
See original GitHub issueWhen 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
- Version used: 0.22.0
- also found here: https://stackoverflow.com/questions/53761722/java-to-kotlin-conversion-extending-abstract-class
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
Since it works in Java I’m inclined to say yes.
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()
):