28

When trying to submit my topology through StormSubmitter, I am getting -

Caused by: java.lang.NoSuchFieldError: INSTANCE  
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:52)

I am using Spring.

I am not initializing HttpClient in Spout/Bolt Constructor. Instead its initialized in constructor of a class that is being fetched from Spring Context in prepare() method of bolt

Code is structured as follows -

SomeBolt.java

@Component
public class SomeBolt extends BaseRichBolt {
    private OutputCollector _collector;
    private SomeClient someClient;

    @Override
    public void prepare(Map conf, TopologyContext context, OutputCollector collector) {
        _collector = collector;
        someClient = AppContext.getBean(SomeClient.class);
    }
}

SomeClient.java

@Component
public class SomeClient {
    private final CloseableHttpClient httpClient;

    public SomeClient() {
        this.httpClient = (httpClient == null ? HttpClients.createDefault() : httpClient);
    }
}

AppContext.java

@Component
public class AppContext implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        AppContext.applicationContext = applicationContext;
    }

    public static <T> T getBean(Class<T> c) {
        return applicationContext.getBean(c);
    }
}
Harsh Moorjani
  • 648
  • 1
  • 5
  • 16
  • Possibly a dependency issue, see http://stackoverflow.com/questions/5106520/hibernate-nosuchfielderror-instance-but-only-with-struts-1 – K.C. Feb 07 '14 at 08:59
  • @K.C. Thanks for the comment. This seemed to be the issue with httpcore:4.2 and 4.3 both being there in uberjar. But even resolving that, did not resolve the issue. – Harsh Moorjani Feb 07 '14 at 11:58
  • @K.C. Seems, this is infact the issue. Our storm package is providing the httpcore-4.2.5 (and hence running anything as `storm jar /path/to/jar.jar` will have duplicate dependency. [Please add your comment as answer and I will accept it] – Harsh Moorjani Feb 07 '14 at 13:02

4 Answers4

19

This is probably a dependency issue.

It's a very unclear error message but I found something similar here: Hibernate NoSuchFieldError INSTANCE but only with Struts 1?

Community
  • 1
  • 1
K.C.
  • 2,084
  • 2
  • 25
  • 38
  • 4
    This is infact the issue. Our storm package is supplying httpcore-4.2.5 (hence running anything as `storm jar /path/to/jar.jar` causes duplicate dependency issue.) – Harsh Moorjani Feb 07 '14 at 13:28
  • anyone figure this out? I am having this same problem. – lockwobr May 27 '14 at 19:18
  • @lockwobr, The issue was that storm was supplying httpcore-4.2.5 while we were dependent of httpcore-4.3. We upgraded httpcore jar in storm libraries to fix this. – Harsh Moorjani Jun 21 '14 at 07:39
9

I faced similar issue like this, In my class path there was two jar contains same class, httpcore-4.3 and apache-httpcomponents-httpcore, I have removed apache-httpcomponents-httpcore from class path solved the issue.

1

Harsh is right its in the storm class path.

So what I did to make this work was remove the httpclient and httpcore that comes with storm and replaced them with newer version 4.3.3 and 4.3.2 respectively. This changes the classpath the works/nimbus/supervisor uses to start. You can run storm classpath and it print the class path out.

[nimbus ~]$ storm classpath
...../storm-0.8.2/lib/httpclient-4.3.3.jar:..../storm-0.8.2/lib/httpcore-4.3.2.jar.....

I am not sure this is a very good work around, I am not sure what part of storm uses this jar.

if you look at the python storm code you see that it will put all jars in the storm root and storm/lib

def get_classpath(extrajars):
    ret = get_jars_full(STORM_DIR)
    ret.extend(get_jars_full(STORM_DIR + "/lib"))
    ret.extend(extrajars)
    return normclasspath(":".join(ret))
lockwobr
  • 1,461
  • 1
  • 15
  • 24
1

I had the below jar files in the path inside the plugin folder:
./var/lib/jenkins/plugins/build-pipeline-plugin/WEB-INF/lib/httpcore-4.2.1.jar
./var/lib/jenkins/plugins/git-client/WEB-INF/lib/httpcore-4.3.2.jar
./var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/httpcore-4.2.4.jar

After, I removed the below file, it worked for me
/var/lib/jenkins/plugins/build-pipeline-plugin/WEB-INF/lib/httpcore-4.2.1.jar