You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Aliaksei Lahachou <al...@gmail.com> on 2013/07/24 10:48:53 UTC

Compiler warnings treated as errors

Hello all,

I think this problem was already discussed here, but I cannot find it. My
problem is that sometimes compiler warnings are treated as errors. For
example:

[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile
(default-compile) on project <...>: Compilation failure: Compilation
failure:
[ERROR] <...>\ImageCaptchaServlet.java:[14,31]
com.sun.image.codec.jpeg.JPEGCodec is Sun proprietary API and may be
removed in a future release
[ERROR] <...>\ImageCaptchaServlet.java:[15,31]
com.sun.image.codec.jpeg.JPEGImageEncoder is Sun proprietary API and may be
removed in a future release

This is not a problem with m-compiler-p version 2.3.2, but it is a problem
in all newer versions (I tried 2.4, 2.5, 2.5.1, 3.0, 3.1).

This behavior seems to be unstable. The source from the example was
compiled successfully, when they were a part of other Maven module. When I
moved it to another module after refactoring, I could not compile it any
more. Both modules are inherited from the same parent and have the same
m-compiler-p configuration (I also compared effective POMs).

I tried building trunk version of m-compiler-p. There, the
CompilerMojoTestCase.testCompilerFork test fails, and it seems to me for
the same reason:

testCompilerFork(org.apache.maven.plugin.compiler.CompilerMojoTestCase)
Time elapsed: 0.09 sec  <<< ERROR!
org.apache.maven.plugin.compiler.CompilationFailureException: Compilation
failure
    at
org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:862)
    at
org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
    at
org.apache.maven.plugin.compiler.CompilerMojoTestCase.testCompilerFork(CompilerMojoTestCase.java:160)


The following code seems a bit strange to me. Why does it throw a
compilation failure exception when there are warnings?

            if ( !errors.isEmpty() )
            {
                throw new CompilationFailureException( errors );
            }
            else
            {
                throw new CompilationFailureException( warnings );
            }

My environment is Windows 7 x64, Oracle JDK 1.6.0_45.

Is this a known problem? Is there a workaround for it? (other than using
version 2.3.2 version of m-compiler-p)

Regards,
htfv (Aliaksei Lahachou)

Re: Compiler warnings treated as errors

Posted by Baptiste MATHUS <ml...@batmat.net>.
Hi Aliaksei,

Thanks for debugging this issue. It would be great if you could file the
corresponding issue in JIRA: http://jira.codehaus.org/browse/MCOMPILER

Btw, if you could attach a test project to it and explain the difference
between expected & actual output, it would be a lot easier to fix the
logging issue.

Thanks a lot.

Le 29 juil. 2013 09:20, "Aliaksei Lahachou" <al...@gmail.com> a
écrit :

> I debugged the compiler plugin and found the problem. The output from the
> javac compiler is the following:
>
> --- BEGIN LOG ---
> <...>\ImageCaptchaServlet.java:14: warning:
> com.sun.image.codec.jpeg.JPEGCodec is Sun proprietary API and may be
> removed in a future release
> import com.sun.image.codec.jpeg.JPEGCodec;
>                                ^
> <...>\ImageCaptchaServlet.java:15: warning:
> com.sun.image.codec.jpeg.JPEGImageEncoder is Sun proprietary API and may be
> removed in a future release
> import com.sun.image.codec.jpeg.JPEGImageEncoder;
>                                ^
> An exception has occurred in the compiler (1.6.0_45). Please file a bug at
> the Java Developer Connection (http://java.sun.com/webapps/bugreport)
> after checking the Bug Parade for duplicates. Include your program and the
> following diagnostic in your report.  Thank you.
> com.sun.tools.javac.code.Symbol$CompletionFailure: class file for
> javax.persistence.GenerationType not found
> --- END LOG ---
>
> So the compiler did fail, but the JavacCompiler.parseModernStream failed to
> parse the last message, it returned a list with 2 elements for the first 2
> warnings. The error message was nowhere in m-compiler-p output, which is
> also strange, because I've seen this message in other modules, and I know
> this error very well.
>
> Compiler plugin finishes successfully, after I added API dependencies to
> the POM.
>
> Regards,
> htfv (Aliaksei Lahachou)
>
>
>
> On Sat, Jul 27, 2013 at 8:46 AM, Anders Hammar <an...@hammar.net> wrote:
>
> > > And why does it think, that compilation failed? The same source is
> > > successfully compiled by the compiler plugin 2.3.2. It could be also
> > > compiled successfully in another module with 2.5.1 and 3.1. The
> compiler
> > > source and target are set to 1.5.
> > >
> >
> > I don't know. You need to debug.
> >
> > /Anders
> >
> >
> > >
> > >
> > > On Wed, Jul 24, 2013 at 12:14 PM, Anders Hammar <an...@hammar.net>
> > wrote:
> > >
> > > > > The following code seems a bit strange to me. Why does it throw a
> > > > > compilation failure exception when there are warnings?
> > > > >
> > > > >             if ( !errors.isEmpty() )
> > > > >             {
> > > > >                 throw new CompilationFailureException( errors );
> > > > >             }
> > > > >             else
> > > > >             {
> > > > >                 throw new CompilationFailureException( warnings );
> > > > >             }
> > > > >
> > > >
> > > > It's due to the wrapping if clause you're not quoting:
> > > >
> > > > if ( failOnError && !compilerResult.isSuccess() )
> > > >
> > > > The compilation has failed as indicated by
> !compilerResult.isSuccess().
> > > >
> > > > /Anders
> > > >
> > >
> >
>

Re: Compiler warnings treated as errors

Posted by Aliaksei Lahachou <al...@gmail.com>.
I debugged the compiler plugin and found the problem. The output from the
javac compiler is the following:

--- BEGIN LOG ---
<...>\ImageCaptchaServlet.java:14: warning:
com.sun.image.codec.jpeg.JPEGCodec is Sun proprietary API and may be
removed in a future release
import com.sun.image.codec.jpeg.JPEGCodec;
                               ^
<...>\ImageCaptchaServlet.java:15: warning:
com.sun.image.codec.jpeg.JPEGImageEncoder is Sun proprietary API and may be
removed in a future release
import com.sun.image.codec.jpeg.JPEGImageEncoder;
                               ^
An exception has occurred in the compiler (1.6.0_45). Please file a bug at
the Java Developer Connection (http://java.sun.com/webapps/bugreport)
after checking the Bug Parade for duplicates. Include your program and the
following diagnostic in your report.  Thank you.
com.sun.tools.javac.code.Symbol$CompletionFailure: class file for
javax.persistence.GenerationType not found
--- END LOG ---

So the compiler did fail, but the JavacCompiler.parseModernStream failed to
parse the last message, it returned a list with 2 elements for the first 2
warnings. The error message was nowhere in m-compiler-p output, which is
also strange, because I've seen this message in other modules, and I know
this error very well.

Compiler plugin finishes successfully, after I added API dependencies to
the POM.

Regards,
htfv (Aliaksei Lahachou)



On Sat, Jul 27, 2013 at 8:46 AM, Anders Hammar <an...@hammar.net> wrote:

> > And why does it think, that compilation failed? The same source is
> > successfully compiled by the compiler plugin 2.3.2. It could be also
> > compiled successfully in another module with 2.5.1 and 3.1. The compiler
> > source and target are set to 1.5.
> >
>
> I don't know. You need to debug.
>
> /Anders
>
>
> >
> >
> > On Wed, Jul 24, 2013 at 12:14 PM, Anders Hammar <an...@hammar.net>
> wrote:
> >
> > > > The following code seems a bit strange to me. Why does it throw a
> > > > compilation failure exception when there are warnings?
> > > >
> > > >             if ( !errors.isEmpty() )
> > > >             {
> > > >                 throw new CompilationFailureException( errors );
> > > >             }
> > > >             else
> > > >             {
> > > >                 throw new CompilationFailureException( warnings );
> > > >             }
> > > >
> > >
> > > It's due to the wrapping if clause you're not quoting:
> > >
> > > if ( failOnError && !compilerResult.isSuccess() )
> > >
> > > The compilation has failed as indicated by !compilerResult.isSuccess().
> > >
> > > /Anders
> > >
> >
>

Re: Compiler warnings treated as errors

Posted by Anders Hammar <an...@hammar.net>.
> And why does it think, that compilation failed? The same source is
> successfully compiled by the compiler plugin 2.3.2. It could be also
> compiled successfully in another module with 2.5.1 and 3.1. The compiler
> source and target are set to 1.5.
>

I don't know. You need to debug.

/Anders


>
>
> On Wed, Jul 24, 2013 at 12:14 PM, Anders Hammar <an...@hammar.net> wrote:
>
> > > The following code seems a bit strange to me. Why does it throw a
> > > compilation failure exception when there are warnings?
> > >
> > >             if ( !errors.isEmpty() )
> > >             {
> > >                 throw new CompilationFailureException( errors );
> > >             }
> > >             else
> > >             {
> > >                 throw new CompilationFailureException( warnings );
> > >             }
> > >
> >
> > It's due to the wrapping if clause you're not quoting:
> >
> > if ( failOnError && !compilerResult.isSuccess() )
> >
> > The compilation has failed as indicated by !compilerResult.isSuccess().
> >
> > /Anders
> >
>

Re: Compiler warnings treated as errors

Posted by Aliaksei Lahachou <al...@gmail.com>.
And why does it think, that compilation failed? The same source is
successfully compiled by the compiler plugin 2.3.2. It could be also
compiled successfully in another module with 2.5.1 and 3.1. The compiler
source and target are set to 1.5.


On Wed, Jul 24, 2013 at 12:14 PM, Anders Hammar <an...@hammar.net> wrote:

> > The following code seems a bit strange to me. Why does it throw a
> > compilation failure exception when there are warnings?
> >
> >             if ( !errors.isEmpty() )
> >             {
> >                 throw new CompilationFailureException( errors );
> >             }
> >             else
> >             {
> >                 throw new CompilationFailureException( warnings );
> >             }
> >
>
> It's due to the wrapping if clause you're not quoting:
>
> if ( failOnError && !compilerResult.isSuccess() )
>
> The compilation has failed as indicated by !compilerResult.isSuccess().
>
> /Anders
>

Re: Compiler warnings treated as errors

Posted by Anders Hammar <an...@hammar.net>.
> The following code seems a bit strange to me. Why does it throw a
> compilation failure exception when there are warnings?
>
>             if ( !errors.isEmpty() )
>             {
>                 throw new CompilationFailureException( errors );
>             }
>             else
>             {
>                 throw new CompilationFailureException( warnings );
>             }
>

It's due to the wrapping if clause you're not quoting:

if ( failOnError && !compilerResult.isSuccess() )

The compilation has failed as indicated by !compilerResult.isSuccess().

/Anders