Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port SimpleImmutableEntry for Android2.2 or below #27

Merged
merged 1 commit into from
Jan 20, 2013

Conversation

komamitsu
Copy link
Member

msgpack-java was crashed on Android 2.2 or below when my application called SequentialMapValueImpl$EntrySetIterator.next(). It is because the method calls java.util.AbstractMap$SimpleImmutableEntry that doesn't exist in Android 2.2 or below.

Then I ported java.util.AbstractMap$SimpleImmutableEntry as org.msgpack.util.PortedImmutableEntry. I saw this commit worked on both Android 2.2 and 4.2.

@muga muga merged commit 88b6823 into msgpack:master Jan 20, 2013
@muga
Copy link
Member

muga commented Jan 20, 2013

Hi! Thank you for your pull request:-) I reviewed and merged your contribution into master branch.

And I changed package name of PortedImmutableEntry that you added into 'org.msgpack.util.android'. Please see.
ca9601e

Thanks,

@komamitsu
Copy link
Member Author

The change of the package name is great. Thank you for your prompt attention.

@progval
Copy link

progval commented Feb 23, 2013

I still have the same bug (with Android 4.2):

E/AndroidRuntime(31829): FATAL EXCEPTION: main
E/AndroidRuntime(31829): java.lang.Error: Unresolved compilation problem: 
E/AndroidRuntime(31829):    AbstractMap.SimpleImmutableEntry cannot be resolved to a type
E/AndroidRuntime(31829): 
E/AndroidRuntime(31829):    at org.msgpack.type.SequentialMapValueImpl$EntrySetIterator.next(SequentialMapValueImpl.java:131)
E/AndroidRuntime(31829):    at org.msgpack.type.SequentialMapValueImpl$EntrySetIterator.next(SequentialMapValueImpl.java:1)
E/AndroidRuntime(31829):    at java.util.AbstractMap.containsKey(AbstractMap.java:193)
E/AndroidRuntime(31829):    at net.progval.android.andquote.utils.OpenQuoteApi$Site.parse_sites(OpenQuoteApi.java:59)

@komamitsu
Copy link
Member Author

Could you give me the following information?

  1. Could you paste your code here?
  2. How did build msgpack-java? Maven?
  3. Did you clean your project? For instance, if you use Eclipse, did you "project -> clean"?

@progval
Copy link

progval commented Feb 23, 2013

.1. Yes, sure.

public class MsgPackUtils {
    // ...
    public static boolean in(MapValue map, String key) {
        return map.containsKey(ValueFactory.createRawValue(key));
    }
}
public class OpenQuoteApi {
    public static class Quote {
        public Quote(MapValue map) {
            // ...
            if (MsgPackUtils.in(map, "note")) {
            // ...

As I modified the code after my previous message, here is the new traceback:

E/AndroidRuntime( 6095): FATAL EXCEPTION: main
E/AndroidRuntime( 6095): java.lang.Error: Unresolved compilation problem: 
E/AndroidRuntime( 6095):    AbstractMap.SimpleImmutableEntry cannot be resolved to a type
E/AndroidRuntime( 6095): 
E/AndroidRuntime( 6095):    at org.msgpack.type.SequentialMapValueImpl$EntrySetIterator.next(SequentialMapValueImpl.java:131)
E/AndroidRuntime( 6095):    at org.msgpack.type.SequentialMapValueImpl$EntrySetIterator.next(SequentialMapValueImpl.java:1)
E/AndroidRuntime( 6095):    at java.util.AbstractMap.containsKey(AbstractMap.java:193)
E/AndroidRuntime( 6095):    at net.progval.android.andquote.utils.MsgPackUtils.in(MsgPackUtils.java:14)
E/AndroidRuntime( 6095):    at net.progval.android.andquote.utils.OpenQuoteApi$Quote.<init>(OpenQuoteApi.java:128)

.2. I put msgpack in the libs/ folder of my Android project and it has been compiled by ant.

.3. yes

By the way, here is my temporary and ugly fix: https://github.com/ProgVal/msgpack-java/commit/d0642a5da1744ef04b2f16dcb9935e41e0ee33de

@komamitsu
Copy link
Member Author

Thank you for the information!

But... I can't reproduce the exception...

Could you give me some additional information?

  1. What is your Android OS trivial version? 4.2.2?
  2. What is your Android device? Nexus7?
  3. Can you run the following Android source code?
public class MainActivity extends Activity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Map<String, String> map = new HashMap<String, String>();
    map.put("msgpack", "foobar");
    try {
      MessagePack messagePack = new MessagePack();
      byte[] raw = messagePack.write(map);
      MapValue mapValue = messagePack.read(raw).asMapValue();
      if (MsgPackUtils.in(mapValue, "msgpack"))
        Toast.makeText(this, "OK", Toast.LENGTH_LONG).show();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

@komamitsu
Copy link
Member Author

One more thing, please tell me the API version (in project.properties) and "android:****SdkVersion" in your project.

@progval
Copy link

progval commented Feb 23, 2013

  1. 4.2.2, with CyanogenMod Nightly
  2. Samsung Galaxy S 3 (GT-9300)
  3. I'll tell you as soon as possible
  4. In project.properties, I have "target: android-8" and in the AndroidManifest.xml: "". I hope that answered the question.

@progval
Copy link

progval commented Feb 23, 2013

.3. I'm still getting an error:

E/AndroidRuntime(20613): FATAL EXCEPTION: main
E/AndroidRuntime(20613): java.lang.Error: Unresolved compilation problem: 
E/AndroidRuntime(20613):    AbstractMap.SimpleImmutableEntry cannot be resolved to a type
E/AndroidRuntime(20613): 
E/AndroidRuntime(20613):    at org.msgpack.type.SequentialMapValueImpl$EntrySetIterator.next(SequentialMapValueImpl.java:131)
E/AndroidRuntime(20613):    at org.msgpack.type.SequentialMapValueImpl$EntrySetIterator.next(SequentialMapValueImpl.java:1)
E/AndroidRuntime(20613):    at java.util.AbstractMap.containsKey(AbstractMap.java:193)
E/AndroidRuntime(20613):    at net.progval.android.andquote.utils.MsgPackUtils.in(MsgPackUtils.java:14)
E/AndroidRuntime(20613):    at net.progval.android.andquote.MainActivity.onCreate(MainActivity.java:95)

while my modified version works.

Thanks for your support

@komamitsu
Copy link
Member Author

Thanks for your additional information :)

I tried with the same conditions you told me except for device (I use Nexus7). But I can't reproduce the crash...

Do you use proguard ?

Well, I'll try Galaxy S 3 the day after tomorrow.

@progval
Copy link

progval commented Feb 24, 2013

I don't use proguard as far as I know.

By the way, I forgot to tell I use ant and not Eclipse.
And for some reason, my configuration won't work anymore, so now I can't compile with any of them… I'm currently working at fixing that issue.

Mitsunori Komatsu notifications@github.com a écrit :

Thanks for your additional information :)

I tried with the same conditions you told me except for device (I use
Nexus7). But I can't reproduce the crash...

Do you use proguard ?

Well, I'll try Galaxy S 3 the day after tomorrow.


Reply to this email directly or view it on GitHub:
#27 (comment)

Sent from my Android phone with K-9 Mail. Please excuse my brevity.

@komamitsu
Copy link
Member Author

I tried it on Galaxy S 3, but I couldn't reproduce the exception...

@muga
Copy link
Member

muga commented Feb 26, 2013

hi @progval,

Please check the problem again after fixing your environment. And can you make a patch? It would be really appreciated in this community:-)

@progval
Copy link

progval commented Feb 26, 2013

@komamitsu Did you try compiling with the same environment as me? (ant + openjdk)
Maybe I messed up somewhere in my project. Do you want to try with it? https://github.com/ProgVal/AndQuote

@muga I fixed my environment, sorry for not notifying you.
About writing a patch, I would if I was able to. But this bug does not make any sense to me.

@progval
Copy link

progval commented Feb 26, 2013

er... guess what...
I just tried again and it works...

Sorry for the inconvenience

@muga
Copy link
Member

muga commented Feb 26, 2013

@progval

you mean that msgpack-java works well on your android 4.2?

@muga
Copy link
Member

muga commented Feb 26, 2013

ok, np:-)

anyway, thank you for your contribution, @komamitsu @progval !!!

@progval
Copy link

progval commented Feb 26, 2013

not totally, but at least there is one bug less.

https://github.com/ProgVal/msgpack-java-android-fixes/commits/master
Explainations :

  • "Fix compatibility with Android." was the dirty fix for this bug. As you can see, I reverted it.
  • "Run 'android create lib-project'." is the only way I found to make it compile (I spend five hours trying to do it without changing MsgPack's code). That's the "environment break" I mentionned above.
  • "Remove classes that are broken with android/ant." simply means there were classes whose import failed when I tried to compile. I simply removed those files, as I do not need them.

@komamitsu
Copy link
Member Author

@progval
Thank you for telling your Android project and your explanations!

I tried to build your project with ant, but some errors occured unfortunately.

[aapt] /home/komamitsu/git/AndQuote/libs/msgpack/bin/AndroidManifest.xml:6: error: Error: No resource found that matches the given name (at 'label' with value '@string/app_name').
[aapt] /home/komamitsu/git/AndQuote/libs/msgpack/bin/AndroidManifest.xml:6: error: Error: No resource found that matches the given name (at 'icon' with value '@drawable/ic_launcher').
      :

BTW, If you reproduce the exception, please tell me again :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants