5

When an Interface with no default method extends Serializable everythings works fine. But When a default method for that interface comes in picture we have a warning that says:

MyInterface.java: serializable class MyInterface has no definition of serialVersionUID

It got intersting when I change that interface to a abstract class. The error disappears.

To sum up the warning happening table is as below:

|----------------------------|------------------|
|            Type            |      WARNING     |
|----------------------------|------------------|
| interface with no defaults |         NO       |
|----------------------------|------------------|
| interface with defaults    |        YES       |
|----------------------------|------------------|
| abstract class             |         NO       |
|----------------------------|------------------|

Is there any reason for that or it's just a bug?

mrphoenix13
  • 679
  • 6
  • 10
  • 1
    This only happens when you use `javac -Xlint`. And -X options are Oracle-specific and not part of any Java specification. This warning appears on 1.8u152 and 9.0.1. – DodgyCodeException Nov 20 '17 at 11:30
  • Do not have such problem when I tried in Eclipse – Yogesh H Shenoy Nov 20 '17 at 11:32
  • @DodgyCodeException Yes. I'm using oracle jdk and I'm using -Xlint. It still is an odd bahaviour. – mrphoenix13 Nov 20 '17 at 11:38
  • Thanks for filing a bug on this. It's now tracked as [JDK-8191637](https://bugs.openjdk.java.net/browse/JDK-8191637). It is indeed a bug that you get a missing serialVersionUID warning on an interface. Since an interface is never serialized, it's pointless for it to have a serialVersionUID. However, you say that an abstract class does not generate a missing svuid warning. For me it does, and it should. Under what circumstances does javac not issue the warning for an abstract class? – Stuart Marks Jan 05 '18 at 01:28
  • Ah. JDK 7 would not issue a warning for serializable abstract classes that were missing serialVersionUID. See [JDK-6356530](https://bugs.openjdk.java.net/browse/JDK-6356530). That was fixed, but where are still cases where javac issues the warning when it shouldn't and possibly doesn't issue a warning when it should. We'll fix them in [JDK-8191637](https://bugs.openjdk.java.net/browse/JDK-8191637). – Stuart Marks Jan 05 '18 at 20:36
  • Hmm, was this really fixed? I'm still able to reproduce it with 8u252. – Sebastian Jun 22 '20 at 12:55

0 Answers0