This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
From conversation with Jean-Francois: I have an unwanted \n when updating Method body. I am using netbeans50_beta2. It is only the case on Windows. It is OK on Solaris .....? Code extract : MessageFormat bodyform = new MessageFormat(create.getBodyText()); Object[] args = new Object[] { mbean.getName() , constructParams , constructSign }; create.setBodyText(bodyform.format(args).substring(1));
Finally I probably see what is wrong. Let me try to clarify several things. Consider method in source: void method() { // here is the body of method {0} with param {1} } > MessageFormat bodyform = new MessageFormat(create.getBodyText()); > Object[] args = new Object[] { mbean.getName() , constructParams , > constructSign }; > create.setBodyText(bodyform.format(args).substring(1)); Then, in your code, method above is in 'create' instance in your code extract. You obtain body text by calling create.getBodyText(). Then, you modify the content of this string: modifiedBodyText = do something with obtained body text and put it back by calling setBodyText(modifiedBodyText); Seems to me that when you obtaining body text, you will get something like that: [ // here is the body of method {0} with param {1} ] When you put it back, you call setBodyText and put there the same string (modified, but without changing new line characters: [ // here is the body of method beanName with param anyParam ] (I consider here you don't using substring(1) anymore). I will write a test for this scenario. In tests, I only tried to put completely new body, so \n characters weren't duplicated. The problem is, that b = getBodyText() and setBodyText(b) will change source, but it is expected it will stay unchanged. getBodyText() returns the area closed to []: void method() {[ // here is the body of method {0} with param {1} ]} setBodyText() then replace area closed to <>: void method() { < // here is the body of method {0} with param {1} >} The workaround with sustring(1) can cause, that when data are obtained from file (not document in editor), there can be '\r\n' characters on windows, it seems to be the reason why it doesn't work only on Windows.
Cc'ing original reporter Jean-Francois.
Test which can be used to reproduce this issue. Checking in cfg-unit.xml; /cvs/java/javacore/test/cfg-unit.xml,v <-- cfg-unit.xml new revision: 1.45; previous revision: 1.44 done Checking in unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/MethodBodyTextTest/testModifyBodyText_MethodBodyTextTest.pass; /cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/MethodBodyTextTest/testModifyBodyText_MethodBodyTextTest.pass,v <-- testModifyBodyText_MethodBodyTextTest.pass new revision: 1.2; previous revision: 1.1 done Checking in unit/src/org/netbeans/jmi/javamodel/codegen/indent/MethodBodyTextTest.java; /cvs/java/javacore/test/unit/src/org/netbeans/jmi/javamodel/codegen/indent/MethodBodyTextTest.java,v <-- MethodBodyTextTest.java new revision: 1.4; previous revision: 1.3 done
Checking in src/org/netbeans/modules/javacore/jmiimpl/javamodel/BehavioralFeatureImpl.java; /cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/BehavioralFeatureImpl.java,v <-- BehavioralFeatureImpl.java new revision: 1.17; previous revision: 1.16 done Checking in test/cfg-unit.xml; /cvs/java/javacore/test/cfg-unit.xml,v <-- cfg-unit.xml new revision: 1.46; previous revision: 1.45 done Checking in test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/MethodBodyTextTest/testCreateWithBodyText_MethodBodyTextTest.pass; /cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/MethodBodyTextTest/testCreateWithBodyText_MethodBodyTextTest.pass,v <-- testCreateWithBodyText_MethodBodyTextTest.pass new revision: 1.2; previous revision: 1.1 done Checking in test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/MethodBodyTextTest/testModifyBodyText_MethodBodyTextTest.pass; /cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/MethodBodyTextTest/testModifyBodyText_MethodBodyTextTest.pass,v <-- testModifyBodyText_MethodBodyTextTest.pass new revision: 1.3; previous revision: 1.2 done Checking in test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/MethodBodyTextTest/testSetBodyText_MethodBodyTextTest.pass; /cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/indent/MethodBodyTextTest/testSetBodyText_MethodBodyTextTest.pass,v <-- testSetBodyText_MethodBodyTextTest.pass new revision: 1.2; previous revision: 1.1 done Checking in test/unit/src/org/netbeans/jmi/javamodel/codegen/indent/MethodBodyTextTest.java; /cvs/java/javacore/test/unit/src/org/netbeans/jmi/javamodel/codegen/indent/MethodBodyTextTest.java,v <-- MethodBodyTextTest.java new revision: 1.5; previous revision: 1.4 done
Reorganization of java component