You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2020/05/01 19:41:14 UTC

[GitHub] [netbeans] errael opened a new pull request #2117: [NETBEANS-4270] account for doc.insertString changing length of inser…

errael opened a new pull request #2117:
URL: https://github.com/apache/netbeans/pull/2117


   …tion
   
   Simple fix. The problem occurs when a hint changes Bundle.properties. Hint processing wants to change a line: delete some content, insert "\r\n". The code assumes that 2 characters are inserted, but the "\r" is filtered out. So the delete, after the insert, corrupts the properties file.
   
   The bug report includes a small project to reproduce the problem.
   
   The bug was introduced by the following change (for a different issue). Before this change, the last step was to insert the "\r\n" so the difference in length didn't matter.
   ```
   /f/repos/main-silver/java.source.base
   $ hg log -r 095e4043efa0 src/org/netbeans/api/java/source/ModificationResult.java
   changeset:   279147:095e4043efa0
   branch:      server_split
   parent:      279146:6e4b43cb7725
   parent:      277049:d05de673f3a8
   user:        Svata Dedic <sd...@netbeans.org>
   date:        Wed Aug 27 15:42:57 2014 +0200
   summary:     Manual merge of jet-main/trunk since approx 22 Apr
   
   
   /f/repos/main-silver/java.source.base
   $ hg diff -c 095e4043efa0 src/org/netbeans/api/java/source/ModificationResult.java
   diff --git a/java.source.base/src/org/netbeans/api/java/source/ModificationResult.java b/java.source.base/src/org/netbeans/api/java/source/ModificationResult.java
   --- a/java.source.base/src/org/netbeans/api/java/source/ModificationResult.java
   +++ b/java.source.base/src/org/netbeans/api/java/source/ModificationResult.java
   @@ -428,10 +428,18 @@
                case REMOVE:
                    doc.remove(diff.getStartPosition().getOffset(), diff.getEndPosition().getOffset() - diff.getStartPosition().getOffset());
                    break;
   -            case CHANGE:
   -                doc.remove(diff.getStartPosition().getOffset(), diff.getEndPosition().getOffset() - diff.getStartPosition().getOffset());
   -                doc.insertString(diff.getStartPosition().getOffset(), diff.getNewText(), null);
   +            case CHANGE: {
   +                // first insert the new content, THEN remove the old one. In situations where the content AFTER the
   +                // change is not writable this ordering allows to replace the content, but if we first delete,
   +                // replacement cannot be inserted into the nonwritable area.
   +                int delta = diff.getNewText().length();
   +                int offs = diff.getStartPosition().getOffset();
   +                int removeLen = diff.getEndPosition().getOffset() - offs;
   +
   +                doc.insertString(offs, diff.getNewText(), null);
   +                doc.remove(delta + offs, removeLen);
                    break;
   +            }
            }
        }
   ```
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] errael commented on pull request #2117: [NETBEANS-4270] account for doc.insertString changing length of inser…

Posted by GitBox <gi...@apache.org>.
errael commented on pull request #2117:
URL: https://github.com/apache/netbeans/pull/2117#issuecomment-622542591


   BTW, if anyone want to look at stack traces, like down to
   `text = ReadWriteUtils.convertToNewlines(text);`
   just ask...


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists