Bug 39736 - JavaModelException on copying read-only CompilationUnits
Summary: JavaModelException on copying read-only CompilationUnits
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.0 M2   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 37749 (view as bug list)
Depends on:
Blocks: 38886
  Show dependency tree
 
Reported: 2003-07-08 06:14 EDT by Adam Kiezun CLA
Modified: 2004-05-17 10:04 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Kiezun CLA 2003-07-08 06:14:13 EDT
20030703
copying of read-only compilation units throws a JavaModelException
which does not sound like a reasonable thing (although it's ok according to 
api) - after all, it's not the file being copied that is modifed, it's the 
copied result

i think it should not complain in that case, modify the file and reset the read-
only flag
Comment 1 Dirk Baeumer CLA 2003-07-08 09:00:05 EDT
Philippe, can you do something here for M2. 
Comment 2 Philipe Mulet CLA 2003-07-08 09:10:03 EDT
I think we did consider this solution a while ago, and did eliminate it.
Need to reinvestigate.
Comment 3 Jerome Lanneluc CLA 2003-07-08 09:44:34 EDT
Adam, I'm not seeing a JavaModelException being thrown outside JDT/Core. 
However I see that 
org.eclipse.jdt.internal.corext.refactoring.Checks#validateModifiesFiles(...) 
checks returns an ERROR status for the file being copied.
Comment 4 Adam Kiezun CLA 2003-07-08 09:49:55 EDT
you need to have the latest

i get this (test case is - make a cu readonly, copy, paste to another package)

!ENTRY org.eclipse.jdt.core 4 966 Jul 08, 2003 15:43:08.159
!MESSAGE File /df/x/c/Df.java is read-only.
!STACK 1
org.eclipse.core.internal.resources.ResourceException: File /df/x/c/Df.java is 
read-only.
	at java.lang.Throwable.<init>(Throwable.java)
	at java.lang.Throwable.<init>(Throwable.java:75)
	at org.eclipse.core.runtime.CoreException.<init>(CoreException.java:35)
	at org.eclipse.core.internal.resources.ResourceException.<init>
(ResourceException.java:39)
	at org.eclipse.core.internal.resources.Workspace.validateSave
(Workspace.java:2140)
	at org.eclipse.core.internal.resources.File.setContents(File.java:271)
	at 
org.eclipse.jdt.internal.core.CopyResourceElementsOperation.processCompilationUn
itResource(CopyResourceElementsOperation.java:258)
	at 
org.eclipse.jdt.internal.core.CopyResourceElementsOperation.processElement
(CopyResourceElementsOperation.java:322)
	at org.eclipse.jdt.internal.core.MultiOperation.processElements
(MultiOperation.java:160)
	at 
org.eclipse.jdt.internal.core.CopyResourceElementsOperation.processElements
(CopyResourceElementsOperation.java:340)
	at org.eclipse.jdt.internal.core.MultiOperation.executeOperation
(MultiOperation.java:90)
	at org.eclipse.jdt.internal.core.JavaModelOperation.execute
(JavaModelOperation.java:365)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run
(JavaModelOperation.java:704)
	at org.eclipse.core.internal.resources.Workspace.run
(Workspace.java:1595)
	at org.eclipse.jdt.internal.core.JavaElement.runOperation
(JavaElement.java:487)
	at org.eclipse.jdt.internal.core.JavaModel.runOperation
(JavaModel.java:486)
	at org.eclipse.jdt.internal.core.JavaModel.copy(JavaModel.java:112)
	at org.eclipse.jdt.internal.core.CompilationUnit.copy
(CompilationUnit.java:327)
	at 
org.eclipse.jdt.internal.corext.refactoring.changes.CopyCompilationUnitChange.do
Peform(CopyCompilationUnitChange.java:33)
	at 
org.eclipse.jdt.internal.corext.refactoring.changes.CompilationUnitReorgChange.p
erform(CompilationUnitReorgChange.java:60)
	at 
org.eclipse.jdt.internal.corext.refactoring.CompositeChange.createUndoList
(CompositeChange.java:122)
	at org.eclipse.jdt.internal.corext.refactoring.CompositeChange.perform
(CompositeChange.java:149)
	at 
org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper$1.run
(RefactoringExecutionHelper.java:80)
	at org.eclipse.jdt.internal.core.BatchOperation.executeOperation
(BatchOperation.java:34)
	at org.eclipse.jdt.internal.core.JavaModelOperation.execute
(JavaModelOperation.java:365)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run
(JavaModelOperation.java:704)
	at org.eclipse.core.internal.resources.Workspace.run
(Workspace.java:1595)
	at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:2895)
	at 
org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper$Operation.run
(RefactoringExecutionHelper.java:78)
	at org.eclipse.jface.operation.ModalContext.runInCurrentThread
(ModalContext.java:302)
	at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:252)
	at org.eclipse.jface.dialogs.ProgressMonitorDialog.run
(ProgressMonitorDialog.java:357)
	at 
org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper.perform
(RefactoringExecutionHelper.java:129)
	at org.eclipse.jdt.internal.ui.refactoring.reorg.ReorgCopyStarter.run
(ReorgCopyStarter.java:70)
	at 
org.eclipse.jdt.internal.ui.refactoring.reorg.PasteAction$JavaElementAndResource
Paster.paste(PasteAction.java:304)
	at org.eclipse.jdt.internal.ui.refactoring.reorg.PasteAction.run
(PasteAction.java:146)
	at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun
(SelectionDispatchAction.java:194)
	at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run
(SelectionDispatchAction.java:172)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:842)
	at org.eclipse.ui.actions.RetargetAction.runWithEvent
(RetargetAction.java:187)
	at org.eclipse.ui.internal.commands.ActionAndContextManager.pressed
(ActionAndContextManager.java:232)
	at org.eclipse.ui.internal.commands.ActionAndContextManager.access$6
(ActionAndContextManager.java:218)
	at 
org.eclipse.ui.internal.commands.ActionAndContextManager$7.widgetSelected
(ActionAndContextManager.java:344)
	at org.eclipse.ui.internal.AcceleratorMenu$2.handleEvent
(AcceleratorMenu.java:68)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:848)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1747)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1383)
	at org.eclipse.ui.internal.Workbench.run(Workbench.java:1366)
	at org.eclipse.core.internal.boot.InternalBootLoader.run
(InternalBootLoader.java:858)
	at org.eclipse.core.boot.BootLoader.run(BootLoader.java:461)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:61)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:40)
	at java.lang.reflect.Method.invoke(Method.java:335)
	at org.eclipse.core.launcher.Main.basicRun(Main.java:291)
	at org.eclipse.core.launcher.Main.run(Main.java:747)
	at org.eclipse.core.launcher.Main.main(Main.java:583)
Comment 5 Jerome Lanneluc CLA 2003-07-08 10:12:32 EDT
Thanks. Was able to reproduce.

Fixed CopyResourceElementsOperation.processCompilationUnit(...) to temporary 
set the read-only flag to false while updating the contents.

Added regression test CopyMoveResourcesTests.testCopyCUReadOnly()
Comment 6 Adam Kiezun CLA 2003-07-11 08:44:54 EDT
i don't see it in 0710 - should it be there?
Comment 7 Jerome Lanneluc CLA 2003-07-11 09:01:56 EDT
No, we didn't contribute a build input for I20030710 (our last build input was 
for I20030708). See our build notes:
http://fullmoon.torolab.ibm.com/downloads/drops/I-I20030710-
200307100800/buildnotes/buildnotes_jdt-core.html
Comment 8 David Audel CLA 2003-07-16 06:14:53 EDT
Verified.
Comment 9 Jerome Lanneluc CLA 2004-05-17 10:04:02 EDT
*** Bug 37749 has been marked as a duplicate of this bug. ***