question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trouble with Context on bitcoinj 0.13.2

See original GitHub issue

Hi, first i had a “You must construct a Context object before using bitcoinj!” even if this version should support automatic Context injection. Test code

final byte[] payloadBytes = Bitcoin.fromHex(hex);
final org.bitcoinj.core.Transaction starting = new org.bitcoinj.core.Transaction(MainNetParams.get(), payloadBytes);
System.out.println("starting:"+starting);  //Exception here

I solve this issue explicitly calling before that code

Context.getOrCreate(MainNetParams.get());

But this works in local, while in appengine I got:

java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "modifyThreadGroup")

turning back to 0.12.3 for now.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
mikehearncommented, Oct 9, 2015

App Engine has a specific, non-standard API for the creation of threads. Any attempt to create a thread in the normal Java manner will fail.

This would be awkward to support in the extreme: the fact that your app works in previous versions of bitcoinj is just blind luck. It’s not something we ever supported, so this is not a “bug” in the pedantic sense.

However there is a simple solution for you: compile your own bitcoinj and in the Threading class, remove the code that initialises USER_THREAD.

0reactions
jloppcommented, Nov 20, 2015

FYI I get the same error while running a unit test in Eclipse after upgrading to BitcoinJ 0.13.3:

org.bitcoinj.store.BlockStoreException: java.lang.IllegalStateException: You must construct a Context object before using bitcoinj!
    at com.bitgo.BitGoService.BlockStore.getStoredBlock(BlockStore.java:138)
    at com.bitgo.BitGoService.BlockStoreTest.putAndGet(BlockStoreTest.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.IllegalStateException: You must construct a Context object before using bitcoinj!
    at org.bitcoinj.core.Context.get(Context.java:77)
    at org.bitcoinj.core.Transaction.getConfidence(Transaction.java:1143)
    at org.bitcoinj.core.Block.parseTransactions(Block.java:219)
    at org.bitcoinj.core.Block.parse(Block.java:233)
    at org.bitcoinj.core.Message.<init>(Message.java:114)
    at org.bitcoinj.core.Message.<init>(Message.java:150)
    at org.bitcoinj.core.Block.<init>(Block.java:117)
    at com.bitgo.BitGoService.BlockStore.getStoredBlock(BlockStore.java:136)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Release notes - bitcoinj
Release notes. Version 0.16.2. This is a bug fix and maintenance release. Notable changes: Support segwit in addSignedInput() methods.
Read more >
Bitcoin Core version 0.13.2 released
This is a new minor version release, including various bugfixes and performance improvements, as well as updated translations. Please report ...
Read more >
Bitcoin Core 0.13.2
This behavior has been changed to return success and to reattempt mempool insertion at the same time transaction rebroadcast is attempted, avoiding a...
Read more >
Index (bitcoinj 0.13.1 API) - javadoc.io
A ThreadFactory that propagates a Context from the creating thread into the new thread. ContextPropagatingThreadFactory(String, int) - Constructor for class org ...
Read more >
[bitcoin-dev] Script Abuse Potential?
Next message: [bitcoin-dev] Bitcoin Core 0.13.2 released ... direct limit on op_cat is it favors what​ ​ ​ I'll dub "context free" analysis, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found