0

I work on a application 100% automatically transcoded from Cobol to Java. In many places, the COBOL have taken shortcuts to eliminate some codes: they code a which generates a return statement while there are other statements after the return.

The problem is the following: those "return" in Java means "unreachable statement" errors for all what's coming after the return in the same method.

I am fine with those errors, but my question: the compiler (OpenJDK) stops at the 1st one (while there many of those + others...). So, it's painful because I have to remove those errors one after the other and rerun the compile each time. Pretty painful !

Is there a way to tell to the compiler "don't stop at 1st error but discover them all" ?

PS: I run it via the ant . Does it make any difference than running the bare compiler from com

Thanks a lot in advance !

didier

Didier Durand
  • 627
  • 7
  • 16
  • 2
    Eclipse is handy for correcting compiler errors -- highlights, navigation, and listing. It will also update "on the fly". –  Aug 05 '11 at 08:13
  • Hi, pst: that's because of Eclipse that I know that there are many other errors. To be more precise: the application is big (9.1 millions lines of Cobol giving as many lines of Java). The process of transcoding to Java then compiling is done every night . It's a batch process: I would like it to go through to have a full report every morning rather than just the 1st errors. So, I can use Eclipse to do a check once a while but not every time. – Didier Durand Aug 05 '11 at 08:27
  • If you use findBugs (or similar) to check your code, it will produce a report, which you can then filter to pick out the kind of errors in which you are interested. – Andrew Fielden Aug 05 '11 at 08:34
  • Seems like a bug in your Cobol-to-Java transcoder. Maybe you can try to somehow fix it/work around it, e.g. try a newer version/a different tool/contact the tool's developers/fix it yourself if it's open-source. – Eli Acherkan Aug 05 '11 at 08:54
  • Hi Eli, it's not a bug in Cobol-to-Java transcoder: Cobol programmers may produce invalid syntax on their still evolving application. We want to detect them all in just 1 compilation. Hence, compiler should not stop on the 1st one – Didier Durand Aug 05 '11 at 10:45
  • @Didier Durand: is the input Cobol code legal (in Cobol) or not? If it is, then the transcoder should output legal Java code. If it isn't, may I suggest catching the errors at the Cobol code level? I don't see much point in running the transcoder on input code that doesn't compile. I understand that I'm not addressing your original request of having the Java compiler continue after the first error, it's just that I want to understand the whole process better. – Eli Acherkan Aug 05 '11 at 11:11
  • @Eli: yes, the generated Cobol is legal: it compiles perfectly as the Cobol compiler accepts that you put a RETURN even if there is code after (that won't be executed of course). But, javac is stricter: in such a case, it generates the usual "unreachable statement" error which is ok for me. My point is to obtain all compiling errors at once, not to change the behavior of those 2 tools which is perfectly correct. regards. didier – Didier Durand Aug 08 '11 at 06:35
  • @Didier Durand: then I still think it's a bug in the transcoder - it should drop the statements after the RETURN. Even if you collect all the Java compilation errors at once, why should you have to fix Cobol code which is legal in itself? – Eli Acherkan Aug 08 '11 at 08:47

3 Answers3

1

You could use a static code checker such as findBugs. It will report any problems like this (and a lot more) with your code.

http://findbugs.sourceforge.net/

Andrew Fielden
  • 3,751
  • 3
  • 31
  • 47
  • Hi Andrew, thanks ! We use Findbugs: the out-of-the box ruleset doesn't rise any issue for unreachable statements. Do you use a specific set of rules ? [Anyway, we need to compile also, so i am looking desperately for the option that allows the compiler to give a full report for our entire source code rather than this abrupt stop at first "unreachable statement" error, – Didier Durand Aug 05 '11 at 08:33
  • Hm that does surprise me Didier. I thought findBugs was very comprehensive in its reporting, and would include unreachable code problems. But then, it's an actual compile error, not a warning. – Andrew Fielden Aug 05 '11 at 08:39
  • FindBugs finds errors in compiled classes. Didier has problems compiling its Java code to classes. FindBugs is thus of no help here. – JB Nizet Aug 05 '11 at 08:43
0

You can use the Eclipse compiler from within Ant - http://www.ant4eclipse.org/node/55 - which in turn can be configured.

The samples on the page shows how to use the Eclipse settings (ant4eclipse is a project to allow compilation of existing eclipse projects with ant).

I have done some work with ant4eclipse but found that it did not scale well for us.

Also note you can add annotations to the generated source to turn off compiler warnings. See Java: How to @SuppressWarnings unreachable code?

Community
  • 1
  • 1
Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
0

PS: I run it via the ant . Does it make any difference than running the bare compiler from com

Shouldn't be a difference, ant is just doing the same.

Thomas
  • 87,414
  • 12
  • 119
  • 157