Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 331904 - StringIndexOutOfBoundsException in Reindenter
Summary: StringIndexOutOfBoundsException in Reindenter
Status: RESOLVED FIXED
Alias: None
Product: PTP
Classification: Tools
Component: Photran.Refactoring Engine (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: 7.0   Edit
Assignee: Photran Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-06 09:58 EST by Rajashekhar Arasanal CLA
Modified: 2011-03-14 15:22 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rajashekhar Arasanal CLA 2010-12-06 09:58:45 EST
Build Identifier: 20100617-1415

This report lists two issues with the indenter:

1.

The indenter crashes with string out of range exception when it was called from the editor on the following program:

program comment_surrounding_goto
    implicit none
    integer anotherlabel

    ! before comment
    assign 10000 to anotherlabel ! line comment
    ! after comment

    ! before comment
10000    goto anotherlabel ! line comment
    ! after comment

end program comment_surrounding_goto

The stack trace is below:

Root exception:
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
	at java.lang.String.substring(Unknown Source)
	at org.eclipse.photran.internal.core.reindenter.StartOfLine.setIndentation(StartOfLine.java:234)
	at org.eclipse.photran.internal.core.reindenter.StartOfLine.reindentStatement(StartOfLine.java:220)
	at org.eclipse.photran.internal.core.reindenter.StartOfLine.reindent(StartOfLine.java:170)
	at org.eclipse.photran.internal.core.reindenter.ShiftBlockVisitor.updateIndentation(ShiftBlockVisitor.java:68)
	at org.eclipse.photran.internal.core.reindenter.ReindentingVisitor.visitToken(ReindentingVisitor.java:83)
	at org.eclipse.photran.internal.core.lexer.Token.accept(Token.java:348)
	at org.eclipse.photran.internal.core.parser.ASTVisitor.traverseChildren(ASTVisitor.java:21)
	at org.eclipse.photran.internal.core.parser.ASTVisitor.visitASTSelectCaseStmtNode(ASTVisitor.java:335)
	at org.eclipse.photran.internal.core.parser.ASTSelectCaseStmtNode.accept(ASTSelectCaseStmtNode.java:81)
	at org.eclipse.photran.internal.core.parser.ASTVisitor.traverseChildren(ASTVisitor.java:21)
	at org.eclipse.photran.internal.core.parser.ASTVisitor.visitASTCaseConstructNode(ASTVisitor.java:74)
	at org.eclipse.photran.internal.core.parser.ASTCaseConstructNode.accept(ASTCaseConstructNode.java:74)
	at org.eclipse.photran.internal.core.parser.ASTVisitor.traverseChildren(ASTVisitor.java:21)
	at org.eclipse.photran.internal.core.parser.ASTVisitor.visitASTListNode(ASTVisitor.java:26)
	at org.eclipse.photran.internal.core.parser.ASTListNode.accept(ASTListNode.java:130)
	at org.eclipse.photran.internal.core.parser.ASTVisitor.traverseChildren(ASTVisitor.java:21)
	at org.eclipse.photran.internal.core.parser.ASTVisitor.visitASTMainProgramNode(ASTVisitor.java:251)
	at org.eclipse.photran.internal.core.parser.ASTMainProgramNode.accept(ASTMainProgramNode.java:100)
	at org.eclipse.photran.internal.core.parser.ASTVisitor.traverseChildren(ASTVisitor.java:21)
	at org.eclipse.photran.internal.core.parser.ASTVisitor.visitASTListNode(ASTVisitor.java:26)
	at org.eclipse.photran.internal.core.parser.ASTListNode.accept(ASTListNode.java:130)
	at org.eclipse.photran.internal.core.parser.ASTVisitor.traverseChildren(ASTVisitor.java:21)
	at org.eclipse.photran.internal.core.parser.ASTVisitor.visitASTExecutableProgramNode(ASTVisitor.java:175)
	at org.eclipse.photran.internal.core.parser.ASTExecutableProgramNode.accept(ASTExecutableProgramNode.java:61)
	at org.eclipse.photran.internal.core.FortranAST.accept(FortranAST.java:53)
	at org.eclipse.photran.internal.core.reindenter.Reindenter.reindent(Reindenter.java:107)
	at org.eclipse.photran.internal.core.reindenter.Reindenter.reindent(Reindenter.java:86)
	at org.eclipse.photran.internal.core.refactoring.RemoveAssignedGotoRefactoring.makeChangesTo(RemoveAssignedGotoRefactoring.java:586)
	at org.eclipse.photran.internal.core.refactoring.RemoveAssignedGotoRefactoring.doCreateChange(RemoveAssignedGotoRefactoring.java:635)
	at org.eclipse.rephraserengine.core.vpg.refactoring.VPGRefactoring.createChange(VPGRefactoring.java:196)
	at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:124)
	at org.eclipse.ltk.core.refactoring.PerformChangeOperation.run(PerformChangeOperation.java:209)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
	at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)

2.

Consider the following program:

program comment_surrounding_goto
    implicit none
    integer anotherlabel

    ! before comment
    assign 1 to anotherlabel ! line comment
    ! after comment

    ! before comment
1   goto anotherlabel ! line comment
    ! after comment

end program comment_surrounding_goto

When the reindenter is called, the comment before the "goto anotherlabel" is lost. Below is the result program:

program comment_surrounding_goto
    implicit none
    integer anotherlabel

    ! before comment
    assign 1 to anotherlabel ! line comment
1   goto anotherlabel ! line comment
	! after comment

end program comment_surrounding_goto


Reproducible: Always

Steps to Reproduce:
1. Copy the sample programs (details section) into the photran editor.
2. Press Ctrl + I
3. For the first issue, the exception StringIndexOutOfBoundsException is thrown.
4. For the second issue, the comments after the ASSIGN statement and before the GOTO statements are lost.
Comment 1 Rajashekhar Arasanal CLA 2010-12-07 00:24:27 EST
Please note that the problem #2 appears only when the statement is labeled. Ex:

    ! before comment
1   goto anotherlabel ! line comment
Comment 2 Jeffrey Overbey CLA 2011-03-14 15:22:46 EDT
This is fixed in HEAD/7.0.  Added test case 09-bug331904.f90