Menu

#46 unparsable file + blank lines

closed
None
1
2002-07-28
2002-05-20
Kees Kuip
No

Jalopy doesn't accept comments after the
class declaration.

This class results in an error in Jalopy :

<pre>
public class TestClass { }
/** Hello World */
</pre>

The error is :
[ERROR] test.java:0:line 4: invalid endline comment.
Use either ML_COMMENT or SL_COMMENT -- /** Hello World
*/ 4:1 4:19
java.lang.IllegalArgumentException: line 4: invalid
endline comment. Use either ML_COMMENT or SL_COMMENT --
/** Hello World */ 4:1 4:19

But what's worse the file is empty after the error.
This is the stacktrace :
java.lang.NullPointerException
at de.hunsicker.io.Copy.file(Copy.java:114)
at de.hunsicker.jalopy.Jalopy.restore(Jalopy.java:1724)
at de.hunsicker.jalopy.Jalopy.format(Jalopy.java:1000)
at
de.hunsicker.jalopy.plugin.console.ConsolePlugin.format(ConsolePlugin.java:937)
at
de.hunsicker.jalopy.plugin.console.ConsolePlugin.main(ConsolePlugin.java:181)
at Jalopy.main(Jalopy.java:76)

I'm using Jalopy-1.0b6.

This release is really good ! Now that the blank lines
are kept it really is an alternative to JIndent.

I noticed that not all blank lines are kept. Only in
certain area's. (Not in the declarations etc.)
It would be nice if blank lines are never removed and
that the "separation" rules only append lines.

Thanks,
Kees Kuip

Discussion

  • Marco Hunsicker

    Marco Hunsicker - 2002-05-20

    Logged In: YES
    user_id=44430

    >Jalopy doesn't accept comments after the
    >class declaration.

    Correct is: Jalopy does not allow *Javadoc* comments as
    endline or end-of-file comments.

    >The error is :
    >[ERROR] test.java:0:line 4: invalid endline comment.
    >Use either ML_COMMENT or SL_COMMENT -- /** Hello World
    >*/ 4:1 4:19
    >java.lang.IllegalArgumentException: line 4: invalid
    >endline comment. Use either ML_COMMENT or SL_COMMENT --
    >/** Hello World */ 4:1 4:19

    Acknowledged. Change the comment to be a multi-line comment
    (/* */) and everything works as expected. I will eventually
    change that behaviour so that in these cases Javadoc
    comments will be treated as multi-line comments
    automatically.

    >But what's worse the file is empty after the error.
    >This is the stacktrace :
    >java.lang.NullPointerException
    > at de.hunsicker.io.Copy.file(Copy.java:114)
    > at de.hunsicker.jalopy.Jalopy.restore(Jalopy.java:1724)
    > at de.hunsicker.jalopy.Jalopy.format(Jalopy.java:1000)

    Could you please describe your setup (OS?) and the steps to
    reproduce this error? I can't reproduce it on my W2K
    machine. Do you have the Jalopy sources? If so, please
    change line 114 to 'if (parent != null && !parent.exists
    ())', I expect this the cause of the error.

    >I noticed that not all blank lines are kept. Only in
    >certain area's. (Not in the declarations etc.)
    >It would be nice if blank lines are never removed and
    >that the "separation" rules only append lines.

    Documentation says:
    "If enabled, retains up to the given number of blank lines
    found in the original source. This only works for method or
    constructor bodies. Note that Jalopy still takes your other
    blank lines settings into account."

    This is so because of the current sorting implemenation.
    Can't do much about that for now.

    M.H.

     
  • Marco Hunsicker

    Marco Hunsicker - 2002-05-20
    • assigned_to: nobody --> marcohu
     
  • Kees Kuip

    Kees Kuip - 2002-05-20

    Logged In: YES
    user_id=54746

    <pre>
    I'm using Redhat linux 7.3 with Sun jdk 1.3.1_03.

    How to reproduce ?
    1. > cd /usr/local/project/projecten/Zeep
    2. create a file called "HelloWorld.java" in that directory.
    The contents of the file is :
    class HelloWorld {}
    /** HelloWorld */
    3. Call Jalopy with the console plugin.
    > java Jalopy HelloWorld.java
    (Notice that I refer to the file with a
    relative pathname !)
    4. The error occurs.

    I think there is a problem with using relative pathnames.
    The first NullpointerException I get in Copy.file() is
    that variable parent is null.
    In the code is :
    File parent = dest.getParentFile();
    I think it must be changed in :
    File parent = dest.getAbsoluteFile().getParentFile();
    (or you can just do dest.mkdirs())
    Now parent is initialised.

    I first took your advise and changed the code that I
    checked if the parent was null. But then another error
    occured. I got an FileNotFoundException. The backupfile
    didn't excist !
    In the Preferences I set the BackupLevel to 0. (I was under
    the impression that if Jalopy fails to parse it just leaves
    the sourcefile untouched)
    This setting results in an interesting sequence of events.
    - In the method format() in Jalopy a backup file is
    generated with the method parse()
    - parse() calls method createBackup() (the destination
    is null)
    - createBackup() calls FileBackup.create() in mode FILE_FILE
    - in FileBackup.create() a NUMBERED backupfile is generated
    - First a backup is made with the copy() method.
    - Then all the method removeObsoleteRevisions() is called.
    This method deletes the current revision if the
    backuplevel less than 1 is (it is 0).
    This results in deleting the file that has just been
    made.

    If I set the backuplevel to 1 everything works allright.
    But that leaves a backupfile in my homedirectory that
    always excists. I have projects with 1000+ files and do
    not want to have that in my homedirectory.

    Kees.

    be

    </pre>

     
  • Marco Hunsicker

    Marco Hunsicker - 2002-05-21

    Logged In: YES
    user_id=44430

    >I think there is a problem with using relative pathnames.
    >The first NullpointerException I get in Copy.file() is
    >that variable parent is null.
    >In the code is :
    > File parent = dest.getParentFile();
    >I think it must be changed in :
    > File parent = dest.getAbsoluteFile().getParentFile();

    I wasn't aware that using java.io.File with relative pathnames
    is that different compared to absolute ones. You are right:
    getAbsoluteFile() works fine! Thanks for your investigations.

    >I first took your advise and changed the code that I
    >checked if the parent was null. But then another error
    >occured. I got an FileNotFoundException. The backupfile
    >didn't excist !

    Yep. Another logic flaw I missed. The fix is to remove
    the "else" clause starting on line 426 in FileBackup.java.
    Thanks again.

    >In the Preferences I set the BackupLevel to 0. (I was under
    >the impression that if Jalopy fails to parse it just leaves
    >the sourcefile untouched)

    But that's what it does! The error shows up because the
    RuntimeException results in a call to restoreBackup(), but
    the backup file was deleted as you found out.

    >If I set the backuplevel to 1 everything works allright.
    >But that leaves a backupfile in my homedirectory that
    >always excists. I have projects with 1000+ files and do
    >not want to have that in my homedirectory.

    You can specify a target directory, but you know that...

    Best regards.
    M.H.

     
  • Marco Hunsicker

    Marco Hunsicker - 2002-05-27
    • status: open --> closed
     
  • Marco Hunsicker

    Marco Hunsicker - 2002-05-27

    Logged In: YES
    user_id=44430

    Fixed with 1.0b7

    Keep blank lines feature may be improved in future version...

     
  • Marco Hunsicker

    Marco Hunsicker - 2002-07-28
    • priority: 5 --> 1
     

Log in to post a comment.