NoSuchFieldError INSTANCE at org.apache.http.impl.io.DefaultHttpRequestWriterFactory

▼魔方 西西 提交于 2019-12-03 09:56:41

org.apache.httpcomponents:httpcore:4.1 -> 4.3.3 means 4.1 is the requested version, which is resolved to 4.3.3 by conflict resolution. Executing something like gradle -q dependencyInsight --configuration compile --dependency httpcore should give you more insight on this.

You should check the build output, and see what jars are actually packaged with your app. Also, using some file manager run a search for BasicLineFormatter.class through the build output (including archives, of course), this should give you a definite answer what jars contain what version of this class.

If there is only one version (4.3.3) this must mean that the other version comes from the container that's running your app. Ways of resolving this depend on the container.

If you do find multiple versions, you can try excluding transitive dependency to httpcore globally in the project (chapter 51.4.7 of user guide).

If you define an exclude for a particular configuration, the excluded transitive dependency will be filtered for all dependencies when resolving this configuration or any inheriting configuration.

Seems like BasicLineFormatter got its static INSTANCE in 4.3-beta1 link and link

mabn

Start your jvm with -verbose:class, it will show which class is being loaded from where.

I had such problems in the past in two scenarios:

  1. one of the jars you're loading has a manifest with Classpath clause which references incorrect version of httpcore.

  2. you're running within some container (tomcat or sth) with own classloaders and some classes are loaded e.g. by the container from a different jar.

I also don't think your code showing resource for the class works as it explicitly uses GenieClient's classloader. Probably using BasicLineFormatter.class.getClassloader() would give different results. But better try with -verbose:class.

Willie Wheeler

Clearly there is some older version of BasicLineFormatter on your classpath, one that has the DEFAULT field instead of INSTANCE. See e.g.

But your classloader is reporting that you're using httpcore-4.3.3, and your Gradle dependency tree backs that up.

So it seems that you have some other JAR that has an old version of BasicLineFormatter in it. You might need to go through your dependency JARs and just look to see whether it is in there. Try a jar tf *.jar | grep 'BasicLineFormatter' to see which JARs might be involved.

Also, this may be relevant. I looked at your tags and it seems you do some Android development. So the following Stack Overflow question may be of interest:

Even if that's not the exact issue, it shows how you might have an old BasicLineFormatter hanging around even if you have the right httpcore dependency.

  1. find httpcore which is of an older version than 4.3
  2. remove the older version of httpcore jar from Referenced Libraries.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!