Cannot resolve method close() on javax.servlet.ServletOutputStream

Hello IntelliJ Community.

I'm using the latest build of IntelliJ IDEA: 11.1.2 #IU-117.418
I have a maven based Java project which contains the following code snippet in a JAX-RS resource class:

@javax.ws.rs.core.Context javax.servlet.http.HttpServletResponse response;
...
javax.servlet.ServletOutputStream stream = response.getOutputStream();
stream.close();


The close method is highlighted red in my editor, with the error message stating: "cannot resolve method close()"; however building the project using Maven 2 (both from within IDEA and standalone from the command line) does not produce any errors / warnings about the close method. (in fact the application runs just fine, as expected)

Using ctrl+click and the "scroll to source button" I've discovered that IDEA believes the classes listed in the code snippet above resolve to the following jars:

javax.ws.rs.core.Context [Maven: com.sun.jersey:jersey-core:1.6]
javax.servlet.http.HttpServletResponse [Maven: com.google.gwt:gwt-user:2.4.0]
javax.servlet.ServletOutputStream [Maven: com.google.gwt:gwt-user:2.4.0]

But there may be some confusion between what IntelliJ believes the resolution is and what the resolution actually is when Maven builds the my pom since ctrl+N ServletOutputStream produces the following list:

ServletOutputStream (javax.servlet) Maven: com.google.gwt:gwt-user:2.4.0
ServletOutputStream (javax.servlet) Maven: org.glassfish:javax.servlet:3.0
ServletOutputStream (javax.servlet) Maven: javax.servlet:servlet-api:2.5

<dependency>      <groupId>com.sun.jersey</groupId>      <artifactId>jersey-server</artifactId>      <version>1.6</version> </dependency>
<dependency>      <groupId>com.google.gwt</groupId>      <artifactId>gwt-user</artifactId>      <version>2.4.0</version>      <scope>provided</scope> </dependency>
<dependency>      <groupId>javax.servlet</groupId>      <artifactId>servlet-api</artifactId>      <version>2.5</version>      <scope>provided</scope> </dependency>
<dependency>      <groupId>com.sun.jersey</groupId>       <artifactId>jersey-grizzly2</artifactId>       <version>1.6</version>       <scope>test</scope> </dependency>



Can you see what I'm missing? Is this an IntelliJ Maven bug or have I configured something incorrectly? Any help is greatly appreciated!

P.S. I've attempted to invalidate the caches and reimport maven projects, neither action had any affect on the unresolved method.

8 comments
Comment actions Permalink

Matthew,

could you please create a minimal Maven project which reproduces the problem, and then create an issue in a tracker?

0
Comment actions Permalink

Hi Roman:

I'd like to, but I'm having trouble reproducing it in a sample project, are there any diagnostics I can generate from the offending project that would help you debug; short of including the project's source?

Thanks

0
Comment actions Permalink

The method close() is inherited from java.io.OutputStream - so does your IDEA project have a JDK configured? (you can check this in File | Project Structure | Project)

0
Comment actions Permalink

I believe I have my JDK configured correctly:

1.png
2.png

0
Comment actions Permalink

At a project level - yes, absolutely. Please check also that modules have correct SDK too.

0
Comment actions Permalink

I am experiencing the exast same problem except with the method write().  It seams to me that after upgrading from 10, IntelliJ does not recognize the methods found in the extended java.io.OutputStream.class.  I have followed the suggested resolution steps and have not had any sucess.

0
Comment actions Permalink

It appears I found the solution to my problem.

If I go into `Project Structure` --> `Module` --> `Dependencies` and move 'Maven: com.google.gwt:gwt-user:2.4.0' below 'Maven: com.google.gwt:gwt-dev:2.4.0' then finds the close() method just fine.  If I move the gwt-user jar above the gwt-dev jar, then it give me the error.

Hope it helps.
Capture.JPG

0
Comment actions Permalink

Thanks Ben, your solution worked for me as well. Seems like this is a bug with the Intellij Maven integration, but without reproduceable steps; I'm not sure what to file. At least we have a hackey workaround for now.

0

Please sign in to leave a comment.