相关文章推荐
小百科
›
Upgrading incompatible issue: NoSuchFieldError: Companion
失望的斑马
11 月前
</noscript><!-- End Google Tag Manager (noscript) --><style>astro-island,astro-slot,astro-static-slot{display:contents}</style><astro-island uid="2j065k" prefix="r4" component-url="/answers/_astro/TemplateHeader.832aa2eb.js" component-export="default" renderer-url="/answers/_astro/client.bb1cf6b8.js" props="{}" ssr="" client="load" opts="{"name":"TemplateHeader","value":true}" await-children=""><header class="_header_4k6rl_1 "><div class="_largeContainer_riqi3_1"><div class="_wrapper_4k6rl_25"><a href="https://www.lightrun.com"><img src="/answers/_astro/logo.51e86106.svg" alt="Lightrun" class="_logoImg_4k6rl_84"/></a><nav class="_navWrapper_4k6rl_94"><div class="_navList_4k6rl_38"><div class="_btnMenu_4k6rl_107"><button class="_item_4k6rl_57">Dev Observability<!-- --> <img src="/answers/_astro/arrow_down.9600d28d.svg" alt="arrow_down"/></button><div class="_wrapperContainer_1xjlr_31 "><div class="_wrapper_1xjlr_1"><p class="titleGradient">Dev Observability</p><div class="_menuList_1xjlr_56"><a href="https://lightrun.com/developer-observability/" class="_link_1xjlr_9">What is Developer Observability?</a><a href="https://lightrun.com/why-lightrun/" class="_link_1xjlr_9">Why Lightrun?</a><a href="https://lightrun.com/architecture/" class="_link_1xjlr_9">The Lightrun Architecture</a><a href="https://lightrun.com/sdk/" class="_link_1xjlr_9">The Lightrun SDK™</a><a href="https://lightrun.com/plugin/" class="_link_1xjlr_9">The Lightrun IDE Plugin</a><a href="https://lightrun.com/security/" class="_link_1xjlr_9">Security</a><a href="https://lightrun.com/comparisons/" class="_link_1xjlr_9">Comparisons</a><a href="https://lightrun.com/integrations/" class="_link_1xjlr_9">Integrations</a></div><div class="_arrow_1xjlr_62 "/></div></div></div><div class="_btnMenu_4k6rl_107"><button class="_item_4k6rl_57">Product<!-- --> <img src="/answers/_astro/arrow_down.9600d28d.svg" alt="arrow_down"/></button><div class="_wrapperContainer_1xjlr_31 _expandedMenuContainer_1xjlr_52"><div class="_wrapper_1xjlr_1"><div class="_productWrapper_1xjlr_76"><div><div class="titleGradient">Architectures</div><div class="_mainBlockMenu_1xjlr_93"><div class="_menuBlock_1xjlr_98"><div class="_subTitleList_1xjlr_81">Deployment Patterns</div><div class="_menuList_1xjlr_56"><a class="_link_1xjlr_9" href="https://lightrun.com/kubernetes-troubleshooting/">Kubernetes Debugging</a><a class="_link_1xjlr_9" href="https://lightrun.com/serverless-debugging/">Serverless Debugging</a><a class="_link_1xjlr_9" href="https://lightrun.com/feature-flag-validation/">Feature Flag Debugging</a></div></div><div class="_menuBlock_1xjlr_98"><div class="_subTitleList_1xjlr_81">Environments</div><div class="_menuList_1xjlr_56"><a class="_link_1xjlr_9" href="https://lightrun.com/enviroments/dev-qa-staging/">Dev/QA/Staging</a><a class="_link_1xjlr_9" href="https://lightrun.com/enviroments/ci-cd-pipelines/">CI/CD</a><a class="_link_1xjlr_9" href="https://lightrun.com/enviroments/production/">Production</a></div></div></div></div><div><div class="titleGradient">Technologies</div><div class="_mainBlockMenu_1xjlr_93"><div class="_menuBlock_1xjlr_98"><div class="_subTitleList_1xjlr_81">IDEs</div><div class="_menuList_1xjlr_56"><a class="_link_1xjlr_9" href="https://lightrun.com/plugin/intellij-idea/">IntelliJ IDEA</a><a class="_link_1xjlr_9" href="https://lightrun.com/plugin/vscode/">Visual Studio Code</a><a class="_link_1xjlr_9" href="https://lightrun.com/plugin/pycharm/">PyCharm</a><a class="_link_1xjlr_9" href="https://lightrun.com/plugin/webstorm/">WebStorm</a><a class="_link_1xjlr_9" href="https://lightrun.com/plugin/vscode-dev/">VSCode.dev</a><a class="_link_1xjlr_9" href="https://lightrun.com/get-a-lightrun-demo/">Rider (Coming Soon!)</a></div></div></div></div><div><div class="titleGradient">Roles</div><div class="_mainBlockMenu_1xjlr_93"><div><a class="_link_1xjlr_9" href="https://lightrun.com/roles/backend-developer/">Backend Developer</a><a class="_link_1xjlr_9" href="https://lightrun.com/roles/devops-sre/">DevOps Engineer/SRE</a><a class="_link_1xjlr_9" href="https://lightrun.com/roles/engineering-leader/">Engineering Leader</a></div></div></div><div><div class="titleGradient">Benefits</div><div class="_mainBlockMenu_1xjlr_93"><div><a class="_link_1xjlr_9" href="https://lightrun.com/use-cases/reduce-mttr/">Reduce MTTR</a><a class="_link_1xjlr_9" href="https://lightrun.com/use-cases/optimize-logging-costs/">Optimize Logging Costs</a><a class="_link_1xjlr_9" href="https://lightrun.com/use-cases/improve-developer-productivity/">Improve Dev Productivity</a><a class="_link_1xjlr_9" href="https://lightrun.com/use-cases/improve-reachability-by-5x/">Improve Reachability</a><a class="_link_1xjlr_9" href="https://lightrun.com/use-cases/reduce-time-to-market/">Reduce Time to Market</a><a class="_link_1xjlr_9" href="https://lightrun.com/use-cases/improve-dora-metrics/">Improve DORA Metrics</a></div></div></div><div><div class="titleGradient">Features</div><div class="_mainBlockMenu_1xjlr_93"><div><a class="_link_1xjlr_9" href="https://lightrun.com/logs/">Dynamic Logs</a><a class="_link_1xjlr_9" href="https://lightrun.com/metrics/">Zero-config Metrics</a><a class="_link_1xjlr_9" href="https://lightrun.com/snapshots/">Snapshots (Virtual Breakpoints)</a><a class="_link_1xjlr_9" href="https://lightrun.com/lightrun-log-optimizer/">Lightrun Log Optimizer™</a><a class="_link_1xjlr_9" href="https://lightrun.com/security/">Security</a><a class="_link_1xjlr_9" href="https://lightrun.com/integrations/">Integrations</a><a class="_link_1xjlr_9" href="https://lightrun.com/integrations/">Comparisons</a></div></div></div></div><div class="_arrow_1xjlr_62 _expandedMenuArrow_1xjlr_72"/></div></div></div><a href="https://lightrun.com/pricing" class="_item_4k6rl_57">Pricing</a><a href="https://docs.lightrun.com" class="_item_4k6rl_57">Docs</a><div class="_btnMenu_4k6rl_107"><button class="_item_4k6rl_57">Resources<!-- --> <img src="/answers/_astro/arrow_down.9600d28d.svg" alt="arrow_down"/></button><div class="_wrapperContainer_1xjlr_31 "><div class="_wrapper_1xjlr_1"><p class="titleGradient">Resources</p><div class="_menuList_1xjlr_56"><a href="https://lightrun.com/categories_resources/case-studies/" class="_link_1xjlr_9">Case Studies</a><a href="https://lightrun.com/categories_resources/data-sheets/" class="_link_1xjlr_9">Data Sheets</a><a href="https://lightrun.com/categories_resources/press/" class="_link_1xjlr_9">Press</a><a href="https://lightrun.com/categories_resources/webinars/" class="_link_1xjlr_9">Webinars</a></div><div class="_arrow_1xjlr_62 "/></div></div></div><a href="https://lightrun.com/blog/" class="_item_4k6rl_57">Blog</a><div class="_btnMenu_4k6rl_107"><button class="_item_4k6rl_57">Company<!-- --> <img src="/answers/_astro/arrow_down.9600d28d.svg" alt="arrow_down"/></button><div class="_wrapperContainer_1xjlr_31 "><div class="_wrapper_1xjlr_1"><p class="titleGradient">Company</p><div class="_menuList_1xjlr_56"><a href="https://lightrun.com/about/" class="_link_1xjlr_9">About Us</a><a href="https://lightrun.com/careers/" class="_link_1xjlr_9">Careers</a><a href="https://lightrun.com/answers/microsoft-typescript-support-some-non-structural-nominal-type-matching" class="_link_1xjlr_9">Community</a><a href="https://go.lightrun.com/contact-us" class="_link_1xjlr_9">Contact Us</a></div><div class="_arrow_1xjlr_62 "/></div></div></div><a href="https://playground.lightrun.com" class="_item_4k6rl_57 _itemWordle_4k6rl_76"><span class="_linkWord_4k6rl_142">Debug 🆆🅾🆁🅳🅻🅴</span></a></div><ul class="_linkList_me6o7_1"><li class="_underLine_me6o7_30"><a href="https://app.lightrun.com/api/oauth/login">Log in</a></li><li class="_item_me6o7_18"><a href="https://lightrun.com/get-a-lightrun-demo/" class="_linkBtn_1pn64_1 _transparent_1pn64_31 ">Book a Demo</a></li><li class="_item_me6o7_18"><a href="https://app.lightrun.com/api/oauth/register" class="_linkBtn_1pn64_1 _fill_1pn64_40 ">Start For Free</a></li></ul></nav><button class="_burger_1et1j_1 " title="Navigation"><span class="_line_1et1j_16"/><span class="_line_1et1j_16"/><span class="_line_1et1j_16"/></button></div><div class="_menu_4k6rl_111 "><div class="_mobileMenu_1r89q_11"><div class="_container_riqi3_1"><ul class="_containerNav_1r89q_1"><li class="_navItem_1r89q_7"><div class="_titleMenuItem_1r89q_32"><span>Dev Observability</span><img src="/answers/_astro/mobile-menu-arrow.803067be.svg" alt="arrow" class="_arrow_1r89q_44 "/></div></li><li class="_navItem_1r89q_7"><div class="_titleMenuItem_1r89q_32"><span>Product</span><img src="/answers/_astro/mobile-menu-arrow.803067be.svg" alt="arrow" class="_arrow_1r89q_44 "/></div></li><li class="_navItem_1r89q_7"><a href="https://lightrun.com/pricing" class="_linkMenuItem_1r89q_32">Pricing</a></li><li class="_navItem_1r89q_7"><a href="https://docs.lightrun.com" class="_linkMenuItem_1r89q_32">Docs</a></li><li class="_navItem_1r89q_7"><div class="_titleMenuItem_1r89q_32"><span>Resources</span><img src="/answers/_astro/mobile-menu-arrow.803067be.svg" alt="arrow" class="_arrow_1r89q_44 "/></div></li><li class="_navItem_1r89q_7"><a href="https://lightrun.com/blog/" class="_linkMenuItem_1r89q_32">Blog</a></li><li class="_navItem_1r89q_7"><div class="_titleMenuItem_1r89q_32"><span>Company</span><img src="/answers/_astro/mobile-menu-arrow.803067be.svg" alt="arrow" class="_arrow_1r89q_44 "/></div></li><li class="_navItem_1r89q_7"><a href="https://playground.lightrun.com" class="_linkMenuItem_1r89q_32">Debug Wordle</a></li></ul><div class="_controlButtons_1r89q_70"><ul class="_linkList_me6o7_1"><li class="_underLine_me6o7_30"><a href="https://app.lightrun.com/api/oauth/login">Log in</a></li><li class="_item_me6o7_18"><a href="https://lightrun.com/get-a-lightrun-demo/" class="_linkBtn_1pn64_1 _transparent_1pn64_31 ">Book a Demo</a></li><li class="_item_me6o7_18"><a href="https://app.lightrun.com/api/oauth/register" class="_linkBtn_1pn64_1 _fill_1pn64_40 ">Start For Free</a></li></ul></div></div></div></div></div></header></astro-island><main><astro-island uid="Psc8e" prefix="r0" component-url="/answers/_astro/Hero.ad6751d8.js" component-export="default" renderer-url="/answers/_astro/client.bb1cf6b8.js" props="{}" ssr="" client="load" opts="{"name":"Hero","value":true}" await-children=""><div class="_hero_9cepa_1"><div class="_container_riqi3_1"><div class="_overlay_9cepa_74"><img src="/answers/_astro/question-mark.9737c128.webp" alt="question-mark" class="_heroImg_9cepa_6"/><div class="_wrapper_9cepa_38"><span class="_stuck_9cepa_79">Stuck on an issue?</span><p class="_description_9cepa_87">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.<br/></p><p class="_description_9cepa_87 _strongText_9cepa_146">And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.</p><button class="_btnHero_9cepa_111">Talk to a Lightrun Answers expert</button></div></div></div></div></astro-island><section class="sectionWrapper _issueSummary_1slku_1"><div class="_container_riqi3_1"><div class="_wrapper_1slku_6"><h1 class="_title_1slku_11">Upgrading incompatible issue: NoSuchFieldError: Companion</h1><a href="https://github.com/square/okhttp/issues/5378" class="_linkUnderline_1slku_16">See original GitHub issue</a></div><div class="_wrapperGrid_1slku_66"><div class="_descriptionWrapper_1slku_31"><div class="_wrapper_1otsw_1 _textContainer_1slku_36 "><div class="_content_1otsw_23"><div><p>Hi,</p> <p>The following code snippets throw an incompatible issue when I try to upgrade okhttp from 3.10.0 to 4.1.0.</p> <pre><code>import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.notNull; import static org.mockito.BDDMockito.then; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.WebSocket; import okhttp3.WebSocketListener; import org.assertj.core.api.Assertions; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; public class TestRxWebSocket { private static final String TEST_MESSAGE = "test message"; private static final String TEST_WS_URL = "wss://test.url/"; @Mock private OkHttpClient mockClient; @Mock private WebSocket mockWebSocket; private ArgumentCaptor<WebSocketListener> listenerCaptor; private RxWebSocket subject; @BeforeMethod public void mockito() { MockitoAnnotations.initMocks(this); @BeforeMethod public void setupSubject() { MockitoAnnotations.initMocks(this); subject = new RxWebSocket(mockClient); listenerCaptor = ArgumentCaptor.forClass(WebSocketListener.class); given(mockClient.newWebSocket(notNull(), listenerCaptor.capture())).willReturn(mockWebSocket); private WebSocketListener getListener() { return listenerCaptor.getValue(); @Test public void connect_shouldConnectToUrl() { ArgumentCaptor<Request> request = ArgumentCaptor.forClass(Request.class); given(mockClient.newWebSocket(request.capture(), notNull())).willReturn(null); subject.connect(TEST_WS_URL).subscribe(); Assertions.assertThat(request.getValue().url().toString()).isEqualTo("https://test.url/"); @Test public void send_whenBeforeConnect_shouldThrowNullPointerException() { subject.send(TEST_MESSAGE).test().assertError(NullPointerException.class); <p>The mockito version is 2.16.0. It works well before. After upgrading, it throws an error:</p> <pre><code>[ERROR] mockito(com.github.princesslana.eriscasper.rx.websocket.TestRxWebSocket) Time elapsed: 1.801 s <<< FAILURE! java.lang.NoSuchFieldError: Companion at okhttp3.internal.Util.<clinit>(Util.kt:69) at okhttp3.OkHttpClient.<clinit>(OkHttpClient.kt:959) at sun.reflect.GeneratedSerializationConstructorAccessor1.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.newInstance(SunReflectionFactoryInstantiator.java:48) at org.objenesis.ObjenesisBase.newInstance(ObjenesisBase.java:73) at org.mockito.internal.creation.instance.ObjenesisInstantiator.newInstance(ObjenesisInstantiator.java:19) at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.createMock(InlineByteBuddyMockMaker.java:185) at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:35) at org.mockito.internal.MockitoCore.mock(MockitoCore.java:65) at org.mockito.Mockito.mock(Mockito.java:1864) at org.mockito.internal.configuration.MockAnnotationProcessor.process(MockAnnotationProcessor.java:36) at org.mockito.internal.configuration.MockAnnotationProcessor.process(MockAnnotationProcessor.java:16) at org.mockito.internal.configuration.IndependentAnnotationEngine.createMockFor(IndependentAnnotationEngine.java:38) at org.mockito.internal.configuration.IndependentAnnotationEngine.process(IndependentAnnotationEngine.java:62) at org.mockito.internal.configuration.InjectingAnnotationEngine.processIndependentAnnotations(InjectingAnnotationEngine.java:57) at org.mockito.internal.configuration.InjectingAnnotationEngine.process(InjectingAnnotationEngine.java:41) at org.mockito.MockitoAnnotations.initMocks(MockitoAnnotations.java:69) at com.github.princesslana.eriscasper.rx.websocket.TestRxWebSocket.mockito(TestRxWebSocket.java:36) 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:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124) at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:455) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222) at org.testng.internal.Invoker.invokeMethod(Invoker.java:520) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:716) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:988) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) at org.testng.TestRunner.privateRun(TestRunner.java:648) at org.testng.TestRunner.run(TestRunner.java:505) at org.testng.SuiteRunner.runTest(SuiteRunner.java:455) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415) at org.testng.SuiteRunner.run(SuiteRunner.java:364) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208) at org.testng.TestNG.runSuitesLocally(TestNG.java:1137) at org.testng.TestNG.runSuites(TestNG.java:1049) at org.testng.TestNG.run(TestNG.java:1017) at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:135) at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeSingleClass(TestNGDirectoryTestSuite.java:112) at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:99) at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:146) at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:373) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:334) at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:119) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:407) </div></div></div></div><div class="_descriptionWrapper_1slku_31"><h3>Issue Analytics</h3><ul class="_analyticsWrapper_1slku_83"><li><span class="_boldTitle_1slku_98">State:</span><img src="/answers/_astro/closed_icon.960d8bad.svg" alt="closed"/></li><li>Created <!-- -->4 years ago</li><li><span class="_boldTitle_1slku_98">Comments:</span><span>6<!-- --> (3 by maintainers)</span></li></ul></div></div></div></section><section class="sectionWrapper _topResultsSection_1fyzj_1"><div class="_container_riqi3_1"><div class="_wrapper_1fyzj_8"><section class="_commentsSection_ywxhf_1"><h4 class="_title_11519_1 "><img src="/answers/_astro/github_icon.a38d9f88.webp" alt="github_icon"/>Top GitHub Comments</h4><div class="_commentsContainer_ywxhf_11"><div class="_commentsWrapper_ywxhf_24"><div class="_itemWrapper_ywxhf_30"><div class="_itemHead_ywxhf_38"><div class="_itemReactions_ywxhf_53"><span class="_count_ywxhf_62">2</span><span class="_description_ywxhf_66">reactions</span></div><a href="https://github.com/square/okhttp/issues/5378#issuecomment-523363744" class="_name_ywxhf_75">dvdmunckhof</a><span class="_itemTitle_ywxhf_71">commented, Aug 21, 2019</span></div><div class="_wrapper_1otsw_1 _scrollContainer_ywxhf_80"><div class="_content_1otsw_23"><div><p>I just had the same issue with OkHttp 4.x when upgrading from 3.x. We’re not using MockWebServer or any other ‘extensions’, just OkHttp, so mismatching versions was not the case.</p> <pre><code>Exception in thread "main" java.lang.NoSuchFieldError: Companion at okhttp3.internal.Util.<clinit>(Util.kt:69) at okhttp3.internal.connection.RealConnectionPool.<clinit>(RealConnectionPool.kt:263) at okhttp3.ConnectionPool.<init>(ConnectionPool.kt:37) at okhttp3.ConnectionPool.<init>(ConnectionPool.kt:39) at okhttp3.OkHttpClient$Builder.<init>(OkHttpClient.kt:438) at [redacted] <p>Eventually I found the cause. Our dependency tree (simplified and stripped):</p> <pre><code>project :main +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.41 | +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.41 | | +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.41 | | \--- org.jetbrains:annotations:13.0 | \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.41 | \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.41 +--- project :subproject | \--- com.squareup.okhttp3:okhttp:4.1.0 | +--- com.squareup.okio:okio:2.2.2 | \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.41
推荐文章