9 Replies Latest reply: Nov 15, 2010 9:07 AM by Darryl Burke RSS

    error in @Override while chaning from JDK1.6 to JDk1.5

    717688
      Hi,

      I am getting following error while migrating from JDK1.6 to JDK1.5.

      Multiple markers at this line
           - implements org.quartz.Job.execute
           - The method execute(JobExecutionContext) of type TransferFiles must override a superclass
           method

      I have a class which implements Job interface having one method execute(JobExecutionContext context) . I am overriding this method inside one of my class by using @Override annotataion.

      It is working absolutely fine in JDK1.6 but while migrating to JDK1.5 it is showing the above error.

      Kindly help me in this regard.

      Thanks,
      AK
        • 1. Re: error in @Override while chaning from JDK1.6 to JDk1.5
          JoachimSauer
          The behaviour of @Override changed between JDK5 and JDK6 (this is actually an undocumented change, "fixing" an implementation fault).

          In JDK5 when you implement an interface method (as opposed to overriding an actual implemented method) and specify @Override, it resulsts in a compile time error.
          In JDK6 when you implement an interface method (as opposed to overriding an actual implemented method) and specify @Override, it's considered correct.

          So to port your code to JDK5, you need to remove the @Override annotation.
          • 2. Re: error in @Override while chaning from JDK1.6 to JDk1.5
            717688
            You are right. But while removing the @Override annotation I am getting runtime error.

            How can I override a interface's method in my class without using @Override annotation.

            Please help me.

            Thanks,
            AK
            • 3. Re: error in @Override while chaning from JDK1.6 to JDk1.5
              JoachimSauer
              user8411781 wrote:
              You are right. But while removing the @Override annotation I am getting runtime error.
              I'm pretty sure that the runtime error has nothing to do with that annotation. The annotation has no effect whatsoever on the compiled code. It's just an additional safety check at compile time.

              If you had provided actual details about the runtime error, then we might be able to comment on that.
              How can I override a interface's method in my class without using @Override annotation.
              You don't actually "override" an interface's method, you implement it. And you can do that simply by leaving out the "@Override" annotation. As I said: @Override is only an additional optional safety check to ensure your method actually overrides (or implements, if you use JDK6) another method. This is useful when the signature of the base method changes: then you'll get a compile time error because the derived classes' method no longer overrides anything.
              • 4. Re: error in @Override while chaning from JDK1.6 to JDk1.5
                791266
                user8411781 wrote:
                You are right. But while removing the @Override annotation I am getting runtime error.
                That runtime error isn't related to the fact that you removed the annotation.

                >
                How can I override a interface's method in my class without using @Override annotation.
                Using the annotation or not does not change if a method is overridden or not. The method will always be overridden, so it sounds like you might have a classpath change, or an older version of the library in 1.5.
                • 5. Re: error in @Override while chaning from JDK1.6 to JDk1.5
                  717688
                  Thank you very much for your kind help. I would like to tell you that by changing my enviroment to JDK1.5 from JDK1.6 it is asking for change the project facet. After changing the Project Facet from 6.0 to 5.0 I am getting error at @Override annotation line.

                  I am sharing my code here.

                  @Override
                       public void execute(JobExecutionContext arg0) throws JobExecutionException {
                            System.out.println("Quartz Scheduler: " + new Date());
                            errFileList.clear();
                            ArrayList<String> inputFileList = new ArrayList<String>();
                            try {
                                 Authenticate.setUser();
                                 inputFileList = getInputFileList(yesterdayDate());
                                 int x = 0;
                                 Iterator<String> inputIterator = inputFileList.iterator();
                                 while (inputIterator.hasNext()) {
                                      String inputFile = inputIterator.next();
                                      StringTokenizer st = new StringTokenizer(inputFile, "&");
                                      String output = null;
                                      while (st.hasMoreTokens()) {
                                           String view = (String) st.nextElement();
                                           if (view.startsWith("view")) {
                                                StringTokenizer st1 = new StringTokenizer(view, "=");
                                                while (st1.hasMoreTokens()) {
                                                     output = (String) st1.nextElement();
                                                }
                                           }
                                      }
                                      x++;
                                      String outputFile = OUTPUT_FILES + output + XML;
                                      getAuthentication(Authenticate.getUserId(), Authenticate
                                                .getPassword());
                                      status = copyfile(inputFile, outputFile, x);
                                      runTime();
                                 }
                                 runDate();
                                 LOG.info("Error Files Are : " + getErrorFileList());
                                 LOG.info("No of Error Files : " + errFileList.size());
                                 if ((null != status) && (errFileList.size() > 0)) {
                                      setSendMail(true);
                                      EmailHandler
                                                .dispatchEmail(toMailList(), Email.ERROR_FILES,
                                                          TransferFiles.getErrorFileList().toString(),
                                                          Email.FROM);
                                 }
                                 // readLogfile(
                                 // "C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/XmlFileTransformation/FileTransform.log"
                                 // );
                            } catch (Exception e) {
                                 System.out.println("Exception" + e);
                                 LOG.error("Exception" + e);
                            }

                       }

                  Here I have two suggestions coming by eclipse.

                  1.create execute method in super type ToolConstants
                  2.Remove @Override annotation.

                  but I have the same method inside an interface named as Job. So after removing the @Override annotation

                  I am getting the following runtime exception.


                  javax.servlet.ServletException: Servlet execution threw an exception


                  root cause

                  java.lang.NoClassDefFoundError: javax/activation/DataSource
                       fileTransform.FileTransServlet.doPost(FileTransServlet.java:52)
                       javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
                       javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

                  Please help me.

                  Thanks,
                  Ak
                  • 6. Re: error in @Override while chaning from JDK1.6 to JDk1.5
                    JoachimSauer
                    user8411781 wrote:
                    Here I have two suggestions coming by eclipse.

                    1.create execute method in super type ToolConstants
                    2.Remove @Override annotation.

                    but I have the same method inside an interface named as Job.
                    How is that relevant to anything?
                    So after removing the @Override annotation

                    I am getting the following runtime exception.


                    javax.servlet.ServletException: Servlet execution threw an exception


                    root cause

                    java.lang.NoClassDefFoundError: javax/activation/DataSource
                         fileTransform.FileTransServlet.doPost(FileTransServlet.java:52)
                         javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
                         javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
                    So why do you think that this exception is in any way related to the @Override annotaton on execute()? It is not!

                    What happened here is that your fixed on problem (by removing "@Override") and could continue on your way of getting your code to run in Java 5. Further down the road you run into another (unrelated) problem. That doesn't mean that fixing your first problem caused the second one. It just uncovered it (i.e. the first problem prevented you from seeing the second one earlier).

                    Something in FileTransServlet references javax.activation.DataSource, which is a type that was introduced in Java 6 and didn't exist in Java 5 (you could include the necessary Java Activation jar files to get access to that type even in Java 5).
                    • 7. Re: error in @Override while chaning from JDK1.6 to JDk1.5
                      717688
                      Hi ,

                      I have downloaded activation.jar and put it in tomcat lib folder as well as in Eclipse class path. But still I am getting the same error

                      java.lang.NoClassDefFoundError: javax/activation/DataSource
                           fileTransform.FileTransServlet.doPost(FileTransServlet.java:52)
                           javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
                           javax.servlet.http.HttpServlet.service(HttpServlet.java:729)


                      Kindly let me know am I right or not?
                      • 8. Re: error in @Override while chaning from JDK1.6 to JDk1.5
                        717688
                        Hi,

                        Thank you very much for your kind help. I put the activation.jar file inside tomcat->common->lib folder and it works fine. Thank you again. If I face any problem I will let you know.

                        Thanks,
                        AK
                        • 9. Re: error in @Override while chaning from JDK1.6 to JDk1.5
                          Darryl Burke
                          Moderator advice: Please read the announcement(s) at the top of the forum listings and the FAQ linked from every page. They are there for a purpose.

                          db