Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compiler warnings #13410

Merged
merged 3 commits into from Sep 9, 2015
Merged

Fix compiler warnings #13410

merged 3 commits into from Sep 9, 2015

Conversation

rjernst
Copy link
Member

@rjernst rjernst commented Sep 9, 2015

We have a handful of compiler warnings, mostly because of passing an
array to varargs methods. This change fixes these warnings and adds
-Werror so we don't get anymore of these warnings.

Note this does not enable deprecation or unchecked type warnings, so
these remain "hidden". We should work towards removing those as well,
but this is a first step.

We have a handful of compiler warnings, mostly because of passing an
array to varargs methods. This change fixes these warnings and adds
-Werror so we don't get anymore of these warnings.

Note this does *not* enable deprecation or unchecked type warnings, so
these remain "hidden". We should work towards removing those as well,
but this is a first step.
@rjernst rjernst added :Delivery/Build Build or test infrastructure v2.1.0 v5.0.0-alpha1 labels Sep 9, 2015
@rmuir
Copy link
Contributor

rmuir commented Sep 9, 2015

Looks great!

Note this does not enable deprecation or unchecked type warnings, so
these remain "hidden". We should work towards removing those as well,
but this is a first step.

Good, it at least prevents warnings of other types from stacking up. How bad is the unchecked situation? We should really open a followup for that one.

Deprecation is more complicated, especially if we want to deprecate our own apis. That one is less important I think.

@rjernst
Copy link
Member Author

rjernst commented Sep 9, 2015

How bad is the unchecked situation?

Hundreds of warnings...well, at least 100

@rmuir
Copy link
Contributor

rmuir commented Sep 9, 2015

Can we also turn on -Xlint ? I don't care if we then have to add e.g. -Xlint:-serial to disable some of the stupid ones, or ones that need fixes, but it would be nice to know where we stand.

@rjernst
Copy link
Member Author

rjernst commented Sep 9, 2015

I turned on -Xlint and disabled the frequent ones I found, and fixed a handful of easy ones. There are some tricky ones we should really look into...

However, while core main/test now passes compile, I get a failure compiling tests for distribution/tar. But there is no warning, or any error at all... @dadoonet Could you try my branch and see if you understand why? I've run with -X but I don't see anything that explains why the failure occurred.

@s1monw
Copy link
Contributor

s1monw commented Sep 9, 2015

However, while core main/test now passes compile, I get a failure compiling tests for distribution/tar. But there is no warning, or any error at all... @dadoonet Could you try my branch and see if you understand why? I've run with -X but I don't see anything that explains why the failure occurred.

this is likely your JVM / Compiler we had problems her with java version "1.8.0_31" so if you run that I'd upgrade

@s1monw
Copy link
Contributor

s1monw commented Sep 9, 2015

this is really weird if you run mvn clean test-compile -X you get the classpath it uses etc. to pass to javac. If I do this manually I get the following error:

warning: [path] bad path element "/Users/simon/projects/elasticsearch/distribution/tar/target/classes": no such file or directory
error: warnings found and -Werror specified
1 error
1 warning

creating target/classes fixes the issue

@s1monw
Copy link
Contributor

s1monw commented Sep 9, 2015

hmm without -Xlint:all it passes

@dadoonet
Copy link
Member

dadoonet commented Sep 9, 2015

Funny. The same is happening in plugins but not for all plugins...
Analysis are working fine. Cloud-azure is failing...

warning: [path] bad path element "/Users/dpilato/.m2/repository/com/sun/xml/bind/jaxb-impl/2.2.3-1/jaxb-api.jar": no such file or directory
warning: [path] bad path element "/Users/dpilato/.m2/repository/com/sun/xml/bind/jaxb-impl/2.2.3-1/activation.jar": no such file or directory
warning: [path] bad path element "/Users/dpilato/.m2/repository/com/sun/xml/bind/jaxb-impl/2.2.3-1/jsr173_1.0_api.jar": no such file or directory
warning: [path] bad path element "/Users/dpilato/.m2/repository/com/sun/xml/bind/jaxb-impl/2.2.3-1/jaxb1-impl.jar": no such file or directory
error: warnings found and -Werror specified
1 error
4 warnings

Looking at this ATM.

@dadoonet
Copy link
Member

dadoonet commented Sep 9, 2015

@rjernst Adding <arg>-Xlint:-path</arg> fixes the issue.

And BTW this is cool stuff because now we can see some cloud-azure code issues! :)

[INFO] -------------------------------------------------------------
[WARNING] COMPILATION WARNING : 
[INFO] -------------------------------------------------------------
[WARNING] /Users/dpilato/Documents/Elasticsearch/dev/es-master/elasticsearch/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AzureComputeServiceSimpleMock.java:[50,23] [static] static variable should be qualified by type name, AzureModule, instead of by an expression
[WARNING] /Users/dpilato/Documents/Elasticsearch/dev/es-master/elasticsearch/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AbstractAzureRepositoryServiceTestCase.java:[50,23] [static] static variable should be qualified by type name, AzureModule, instead of by an expression
[WARNING] /Users/dpilato/Documents/Elasticsearch/dev/es-master/elasticsearch/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AzureComputeServiceTwoNodesMock.java:[54,23] [static] static variable should be qualified by type name, AzureModule, instead of by an expression
[INFO] 3 warnings 

@dadoonet
Copy link
Member

dadoonet commented Sep 9, 2015

Just wondering if we should add a maven property like

<lint.level>-Werror</lint.level>

And then define instead of <arg>-Werror</arg>:

<arg>${xlint.level}</arg>

So we could potentially run: mvn clean install -Dlint.level= which will not stop the build but WARN errors

@dadoonet
Copy link
Member

dadoonet commented Sep 9, 2015

@rjernst If you don't want to bypass path checks for each module, then add in parent pom:

<properties>
    <xlint.path></xlint.path>
</properties>

And:

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.3</version>
                    <configuration>
                        <fork>true</fork>
                        <maxmem>512m</maxmem>
                        <!-- REMOVE WHEN UPGRADE:
                             see https://jira.codehaus.org/browse/MCOMPILER-209 it's a bug where
                             incremental compilation doesn't work unless it's set to false causeing
                             recompilation of the entire codebase each time without any changes. Should
                             be fixed in version > 3.1
                         -->
                        <useIncrementalCompilation>false</useIncrementalCompilation>
                        <showWarnings>true</showWarnings>
                        <compilerArgs>
                            <arg>-XDignore.symbol.file</arg>
                            <arg>-Xlint:all</arg>
                            <arg>${xlint.path}</arg>
                            <arg>-Xlint:-cast</arg>
                            <arg>-Xlint:-deprecation</arg>
                            <arg>-Xlint:-fallthrough</arg>
                            <arg>-Xlint:-overrides</arg>
                            <arg>-Xlint:-rawtypes</arg>
                            <arg>-Xlint:-serial</arg>
                            <arg>-Xlint:-try</arg>
                            <arg>-Xlint:-unchecked</arg>
                            <arg>-Werror</arg>
                        </compilerArgs>
                    </configuration>
                </plugin>

In distribution/pom.xml:

<properties>
    <xlint.path>-Xlint:-path</xlint.path>
</properties>

Same in cloud-azure (and may be some others)...

@rjernst
Copy link
Member Author

rjernst commented Sep 9, 2015

Just wondering if we should add a maven property

No, I don't think we should do that, because the next step is "let's set the default back to warn". This PR fixes issues, we don't want to go backwards from there. And there are some we really need to investigate (see some of the TODOs I added in this).

@rjernst
Copy link
Member Author

rjernst commented Sep 9, 2015

@dadoonet thanks for the suggestion on parameterizing -Xling:-path. I actually want to just be able to add additional compiler args within a child pom, eg core. This way the warning removals can be isolated to the modules that need them, instead of allowing leniency in all modules.

@dadoonet
Copy link
Member

dadoonet commented Sep 9, 2015

@rjernst then add in parent pom:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.3</version>
    <configuration>
        <fork>true</fork>
        <maxmem>512m</maxmem>
        <!-- REMOVE WHEN UPGRADE:
             see https://jira.codehaus.org/browse/MCOMPILER-209 it's a bug where
             incremental compilation doesn't work unless it's set to false causeing
             recompilation of the entire codebase each time without any changes. Should
             be fixed in version > 3.1
         -->
        <useIncrementalCompilation>false</useIncrementalCompilation>
        <showWarnings>true</showWarnings>
        <compilerArgs>
            <arg>-XDignore.symbol.file</arg>
            <arg>-Xlint:all</arg>
            <arg>-Xlint:-path</arg>
            <arg>-Werror</arg>
        </compilerArgs>
    </configuration>
</plugin>

In core/pom.xml:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <compilerArgs>
            <arg>-XDignore.symbol.file</arg>
            <arg>-Xlint:all</arg>
            <arg>-Xlint:-path</arg>
            <arg>-Werror</arg>
            <arg>-Xlint:-cast</arg>
            <arg>-Xlint:-deprecation</arg>
            <arg>-Xlint:-fallthrough</arg>
            <arg>-Xlint:-overrides</arg>
            <arg>-Xlint:-rawtypes</arg>
            <arg>-Xlint:-serial</arg>
            <arg>-Xlint:-try</arg>
            <arg>-Xlint:-unchecked</arg>
        </compilerArgs>
    </configuration>
</plugin>

But you don't really inherit from parent pom. You have to declare again all compilerArgs.

@dadoonet
Copy link
Member

dadoonet commented Sep 9, 2015

Ok so here is a better solution.

In /pom.xml:

    <properties>
        <xlint.options/>
    </properties>

...

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.3</version>
                    <configuration>
                        <fork>true</fork>
                        <maxmem>512m</maxmem>
                        <!-- REMOVE WHEN UPGRADE:
                             see https://jira.codehaus.org/browse/MCOMPILER-209 it's a bug where
                             incremental compilation doesn't work unless it's set to false causeing
                             recompilation of the entire codebase each time without any changes. Should
                             be fixed in version > 3.1
                         -->
                        <useIncrementalCompilation>false</useIncrementalCompilation>
                        <showWarnings>true</showWarnings>
                        <compilerArgs>
                            <arg>-XDignore.symbol.file</arg>
                            <arg>-Xlint:all</arg>
                            <arg>-Xlint:-path</arg>
                            <arg>${xlint.options}</arg>
                            <arg>-Werror</arg>
                        </compilerArgs>
                    </configuration>
                </plugin>

In core/pom.xml:

    <properties>
        <xlint.options>-Xlint:-cast,-deprecation,-fallthrough,-overrides,-rawtypes,-serial,-try,-unchecked</xlint.options>
    </properties>

That said, there are also some deprecated classes in plugins, so I would also add in parent pom -deprecation option.

@rjernst
Copy link
Member Author

rjernst commented Sep 9, 2015

@dadoonet @s1monw Thanks for maven help. I've added suppressions and ignores specific to each module where needed. I think this is ready.

@rjernst
Copy link
Member Author

rjernst commented Sep 9, 2015

Pushing as this really hasn't changed other than limiting which xlint options are used.

rjernst added a commit that referenced this pull request Sep 9, 2015
@rjernst rjernst merged commit 9d71f07 into elastic:master Sep 9, 2015
@rjernst rjernst changed the title Build: Fix compiler warnings Fix compiler warnings Sep 9, 2015
@rjernst rjernst deleted the you_were_warned branch September 9, 2015 21:05
@mark-vieira mark-vieira added the Team:Delivery Meta label for Delivery team label Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Delivery/Build Build or test infrastructure Team:Delivery Meta label for Delivery team v2.1.0 v5.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants