I have strange behavior of the static final values in my interface:
public interface IDictionaryErrorTypes {
final static int ERROR_UNKNOWN = 0;
final static int ERROR_XML = 1;
final static int ERROR_CONNECTION = 3;
}
public interface IDictionaryListModel extends IDictionaryErrorTypes,
//... and other interfaces
{
}
public class DictionaryListModel implements IDictionaryListModel {
// ... some code ...
private int getErrorCode(Exception error) {
// determinate the error code
if (error instanceof ParserConfigurationException
|| error instanceof SAXException
|| error instanceof SAXParseException) {
return ERROR_XML;
} else if (error instanceof UnknownHostException
|| error instanceof MalformedURLException
|| error instanceof IOException) {
return ERROR_CONNECTION;
}
return ERROR_UNKNOWN;
}
And now when I run the application ERROR_XML, ERROR_CONNECTION and ERROR_UNKNOWN values equals ZERO – 0. It seems to me very strange. Please look at attached image

If I use in my model IDictionaryErrorTypes.ERROR_CONNECTION it still has the same behavior. But if I remove the "implements IDictionaryErrorTypes" and then use IDictionaryErrorTypes.ERROR_CONNECTION it works – constant values are exactly as they sound be.
When I use class instead of interface it also works fine.
Can someone explain this behavior? (p.s. Im using android platform)
p.s.(2) I also experimented by adding/removing “final”, “static”, “public” keywords ( That is why interface declaration in the image and code about a little bit differ). But behavior is the same
smali code of the WORKING VERSION (using class instead of interface):
.method private getErrorCode(Ljava/lang/Exception;)I
.registers 3
.parameter "error"
.prologue
.line 145
instance-of v0, p1, Ljavax/xml/parsers/ParserConfigurationException;
if-nez v0, :cond_c
.line 146
instance-of v0, p1, Lorg/xml/sax/SAXException;
if-nez v0, :cond_c
.line 147
instance-of v0, p1, Lorg/xml/sax/SAXParseException;
if-eqz v0, :cond_e
.line 148
:cond_c
const/4 v0, 0x1
.line 154
:goto_d
return v0
.line 149
:cond_e
instance-of v0, p1, Ljava/net/UnknownHostException;
if-nez v0, :cond_1a
.line 150
instance-of v0, p1, Ljava/net/MalformedURLException;
if-nez v0, :cond_1a
.line 151
instance-of v0, p1, Ljava/io/IOException;
if-eqz v0, :cond_1c
.line 152
:cond_1a
const/4 v0, 0x3
goto :goto_d
.line 154
:cond_1c
const/4 v0, 0x0
goto :goto_d
.end method
// class instead of interface
.class public Ltj/zar/projects/kathtranslator/interfaces/common/IDictionaryErrorTypes;
.super Ljava/lang/Object;
.source "IDictionaryErrorTypes.java"
# static fields
.field public static final ERROR_CONNECTION:I = 0x3
.field public static final ERROR_UNKNOWN:I = 0x0
.field public static final ERROR_XML:I = 0x1
# direct methods
.method public constructor <init>()V
.registers 1
.prologue
.line 3
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
return-void
.end method
smali code of the UNWORKING VERSION:
.method private getErrorCode(Ljava/lang/Exception;)I
.registers 3
.parameter "error"
.prologue
.line 145
instance-of v0, p1, Ljavax/xml/parsers/ParserConfigurationException;
if-nez v0, :cond_c
.line 146
instance-of v0, p1, Lorg/xml/sax/SAXException;
if-nez v0, :cond_c
.line 147
instance-of v0, p1, Lorg/xml/sax/SAXParseException;
if-eqz v0, :cond_e
.line 148
:cond_c
const/4 v0, 0x1
.line 154
:goto_d
return v0
.line 149
:cond_e
instance-of v0, p1, Ljava/net/UnknownHostException;
if-nez v0, :cond_1a
.line 150
instance-of v0, p1, Ljava/net/MalformedURLException;
if-nez v0, :cond_1a
.line 151
instance-of v0, p1, Ljava/io/IOException;
if-eqz v0, :cond_1c
.line 152
:cond_1a
const/4 v0, 0x3
goto :goto_d
.line 154
:cond_1c
const/4 v0, 0x0
goto :goto_d
.end method
// interface
.class public interface abstract Ltj/zar/projects/kathtranslator/interfaces/common/IDictionaryErrorTypes;
.super Ljava/lang/Object;
.source "IDictionaryErrorTypes.java"
# static fields
.field public static final ERROR_CONNECTION:I = 0x3
.field public static final ERROR_UNKNOWN:I = 0x0
.field public static final ERROR_XML:I = 0x1
solve
Ive cleaned up the project, changed emulator to real device and wrote some test.
Results
It seems a debugger problem:
As you can see in the image error is “3” and ERROR_CONNECTION is “0”. And device actually runs the next string (green string), that means that debugger thinking that 3 == 0, but actually its 3 == 3
Conclusion
Debugger bug.

I think that the only possible explanation is that you have something broken in you edit / build / run / debug procedures, and you are actually running a different version of the code than you think you are.
The evidence for this is that you have decompiled the two versions of the class that you believe that you are running, and the decompiled code clearly shows that:
But when you execute the code (supposedly) it clearly behaves differently to what those bytecodes say.
I can only see one plausible explanation: you are not executing those bytecodes. Instead, you are executing a different version of the bytecodes. In short, you are not recompiling / rebuilding / redeploying everything that needs to be … done.
The debugger output is interesting because it tends to confirm this hypothesis, in that it seems to say that your executable has a copy of the interface with constants that are different from what your source code says. (It could also be a debugger bug … but that is too large a coincidence.) However, the debugger output itself doesn’t explain the behaviour of your app, because the app is not using those values.