Fix erroneous constant propagation in JsProperty field.

JsProperty fields that where not written to in Java, of primitive type,
initiliazed at declaration explicitly to the default value where marked
as final by Finalizer. In turn DeadCodeElimination would consider them
as constants and ended up propagating the constant value incorrectly.

Change-Id: I9ef00c00f99eafd7be25153d3f623f533e7179d7
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/Finalizer.java b/dev/core/src/com/google/gwt/dev/jjs/impl/Finalizer.java
index 60df1ab..bebe4ea 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/Finalizer.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/Finalizer.java
@@ -73,9 +73,10 @@
 
     @Override
     public void exit(JField x, Context ctx) {
-      if (!x.isVolatile()) {
-        maybeFinalize(x);
+      if (x.isVolatile() || x.canBeImplementedExternally() || x.canBeReferencedExternally()) {
+        return;
       }
+      maybeFinalize(x);
     }
 
     @Override
diff --git a/user/test/com/google/gwt/core/interop/JsPropertyTest.java b/user/test/com/google/gwt/core/interop/JsPropertyTest.java
index dbf9b25..e3fb9e7 100644
--- a/user/test/com/google/gwt/core/interop/JsPropertyTest.java
+++ b/user/test/com/google/gwt/core/interop/JsPropertyTest.java
@@ -503,13 +503,30 @@
     @JsProperty
     public String field;
   }
-  private native String getB(B b)/*-{
+
+  private native String getB(B b) /*-{
     return b.field;
   }-*/;
 
-  public void testNotReadExpoprtedFieldNotPruned() {
+  public void testNotReadExportedFieldNotPruned() {
     B b = new B();
     b.field = "secret";
     assertEquals("secret", getB(b));
   }
+
+  @JsType
+  static class ClassWithFieldNotWrittenInJava {
+    public int fieldNotWrittenInJava = 0;
+  }
+
+  private native String setFieldNotWrittenInJava(Object obj, int value) /*-{
+    obj.fieldNotWrittenInJava = value;
+  }-*/;
+
+  public void testFieldNotWrittenInJava() {
+    ClassWithFieldNotWrittenInJava obj = new ClassWithFieldNotWrittenInJava();
+    assertEquals(0, obj.fieldNotWrittenInJava);
+    setFieldNotWrittenInJava(obj, 2);
+    assertEquals(2, obj.fieldNotWrittenInJava);
+  }
 }