# Accidental override when using third party Java interface and extending RuntimeException in kotlin

**URL:** <https://discuss.kotlinlang.org/t/accidental-override-when-using-third-party-java-interface-and-extending-runtimeexception-in-kotlin/7658>\
**Category:** Support\
**Created:** [May 2, 2018, 6:30pm UTC](https://discuss.kotlinlang.org/t/accidental-override-when-using-third-party-java-interface-and-extending-runtimeexception-in-kotlin/7658 "2018-05-02T18:30:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![aditzel](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/aditzel/32/5079_2.png) [@aditzel](https://discuss.kotlinlang.org/u/aditzel)\
**Post date:** [May 2, 2018, 6:30pm UTC](https://discuss.kotlinlang.org/t/accidental-override-when-using-third-party-java-interface-and-extending-runtimeexception-in-kotlin/7658/1 "2018-05-02T18:30:17Z")

</div>

Hi,

I’ve been searching on google and stackoverflow and even here for how to handle the error I’m running, but I haven’t found something that addresses the particular thing I’m running into.

I have a Spring Boot (1.5.X) application that I’m converting from Java to Kotlin. Prior to the migration I followed this tutorial in order to add GraphQL support to my service: [Build a GraphQL Server with Spring Boot | Pluralsight | Pluralsight](https://www.pluralsight.com/guides/building-a-graphql-server-with-spring-boot)

The issue comes when trying to convert the following Java class to Kotlin:

Java Version:

```
public class BookNotFoundException extends RuntimeException implements GraphQLError {

    private Map<String, Object> extensions = new HashMap<>();

    public BookNotFoundException(String message, Long invalidBookId) {
        super(message);
        extensions.put("invalidBookId", invalidBookId);
    }

    @Override
    public List<SourceLocation> getLocations() {
        return null;
    }

    @Override
    public Map<String, Object> getExtensions() {
        return extensions;
    }

    @Override
    public ErrorType getErrorType() {
        return ErrorType.DataFetchingException;
    }
}

```

Kotlin version (converted via IntelliJ):

```
class BookNotFoundException(message: String, invalidBookId: Long?): RuntimeException(message), GraphQLError {

    private val extensions = HashMap<String, Any>()

    init {
        extensions["invalidBookId"] = invalidBookId as Any
    }

    override fun getMessage(): String {
        return super.message
    }

    override fun getLocations(): List<SourceLocation>? {
        return null
    }

    override fun getExtensions(): Map<String, Any> {
        return extensions
    }

    override fun getErrorType(): ErrorType {
        return ErrorType.DataFetchingException
    }
}

```

The _ **GraphQLError** _ interface is a third party interface from the **_graphql-java project_**.

When I try to implement the getMessage() method I get the following error:

> ```
> Accidental override: The following declarations have the same JVM signature (getMessage()Ljava/lang/String;):
> fun <get-message>(): String? defined in graphqlpoc.exception.BookNotFoundException
> fun getMessage(): String defined in graphqlpoc.exception.BookNotFoundException
> 
> ```

And if I don’t attempt to implement the getMessage() method I get the following error:

> Class ‘BookNotFoundException’ is not abstract and does not implement abstract member public abstract fun getMessage(): String! defined in graphql.GraphQLError

Is there an easy way to get around this? Or should I simply keep the Exception class in Java?

---

<div class="post-metadata">

**Author:** ![Beholder](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/beholder/32/2078_2.png) [@Beholder](https://discuss.kotlinlang.org/u/Beholder)\
**Post date:** [May 3, 2018, 2:39pm UTC](https://discuss.kotlinlang.org/t/accidental-override-when-using-third-party-java-interface-and-extending-runtimeexception-in-kotlin/7658/2 "2018-05-03T14:39:30Z")

</div>

Looks more like a bug, than a feature… I think we should create issue for this.

---

<div class="post-metadata">

**Author:** ![ilya.gorbunov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ilya.gorbunov/32/1645_2.png) [@ilya.gorbunov](https://discuss.kotlinlang.org/u/ilya.gorbunov)\
**Post date:** [May 3, 2018, 4:12pm UTC](https://discuss.kotlinlang.org/t/accidental-override-when-using-third-party-java-interface-and-extending-runtimeexception-in-kotlin/7658/3 "2018-05-03T16:12:20Z")

</div>

This issue is tracked as KT-6653, there’s a comment covering the case about implementing exception message: [https://youtrack.jetbrains.com/issue/KT-6653#comment=27-2666539](https://youtrack.jetbrains.com/issue/KT-6653#comment=27-2666539)

---

<div class="post-metadata">

**Author:** ![Beholder](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/beholder/32/2078_2.png) [@Beholder](https://discuss.kotlinlang.org/u/Beholder)\
**Post date:** [May 3, 2018, 4:35pm UTC](https://discuss.kotlinlang.org/t/accidental-override-when-using-third-party-java-interface-and-extending-runtimeexception-in-kotlin/7658/4 "2018-05-03T16:35:42Z")

</div>

And there are currently no workaround for it?

---

<div class="post-metadata">

**Author:** ![aditzel](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/aditzel/32/5079_2.png) [@aditzel](https://discuss.kotlinlang.org/u/aditzel)\
**Post date:** [May 3, 2018, 5:34pm UTC](https://discuss.kotlinlang.org/t/accidental-override-when-using-third-party-java-interface-and-extending-runtimeexception-in-kotlin/7658/5 "2018-05-03T17:34:51Z")

</div>

Thank you for linking the ticket, @ilya.gorbunov! Like @Beholder I am curious: is there a workaround for this particular use case? Looking at KT-6653 it doesn’t seem as if there’s any way around this.

---

<div class="post-metadata">

**Author:** ![Inego](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/inego/32/4604_2.png) [@Inego](https://discuss.kotlinlang.org/u/Inego)\
**Post date:** [October 5, 2020, 5:29am UTC](https://discuss.kotlinlang.org/t/accidental-override-when-using-third-party-java-interface-and-extending-runtimeexception-in-kotlin/7658/6 "2020-10-05T05:29:05Z")

</div>

If you can use Java alongside Kotlin in your project, a sad “workaround” is to write this particular class in Java.

---

<div class="post-metadata">

**Author:** ![nuthanprasad](https://avatars.discourse-cdn.com/v4/letter/n/cab0a1/32.png) [@nuthanprasad](https://discuss.kotlinlang.org/u/nuthanprasad)\
**Post date:** [April 1, 2025, 9:59am UTC](https://discuss.kotlinlang.org/t/accidental-override-when-using-third-party-java-interface-and-extending-runtimeexception-in-kotlin/7658/7 "2025-04-01T09:59:06Z")

</div>

Is this issue, still not resolved? writing a java class alongside Kotlin is not an option in my project. Is there a fix for this ?
