Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solving AssertionFailedException TextFileChange.releaseDocument #2441

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,40 @@ public void initializeValidationData(IProgressMonitor monitor) {

@Override
public RefactoringStatus isValid(IProgressMonitor monitor) throws CoreException {
if (monitor == null)
monitor= new NullProgressMonitor();
if (monitor == null) {
monitor = new NullProgressMonitor();
}
try {
monitor.beginTask("", 1); //$NON-NLS-1$
if (fValidationState == null)
throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), "TextFileChange has not been initialialized")); //$NON-NLS-1$
monitor.beginTask("Validating refactoring status...", 1);

// Check for cancellation before proceeding
if (monitor.isCanceled()) {
System.out.println("Operation canceled before validation check.");
return RefactoringStatus.createErrorStatus("Operation was canceled.");
}

if (fValidationState == null) {
throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(),
"TextFileChange has not been initialized"));
}

boolean needsSaving = needsSaving();
RefactoringStatus result = fValidationState.isValid(needsSaving);

boolean needsSaving= needsSaving();
RefactoringStatus result= fValidationState.isValid(needsSaving);
if (needsSaving) {
result.merge(Changes.validateModifiesFiles(new IFile[] { fFile}));
result.merge(Changes.validateModifiesFiles(new IFile[]{fFile}));
} else {
// we are reading the file. So it should be at least in sync
result.merge(Changes.checkInSync(new IFile[] { fFile}));
result.merge(Changes.checkInSync(new IFile[]{fFile}));
}

// Log final validation state
System.out.println("Validation completed successfully. Needs saving: " + needsSaving);
return result;

} catch (CoreException e) {
System.err.println("Error during validation: " + e.getMessage());
throw e; // Re-throw exception after logging

} finally {
monitor.done();
}
Expand All @@ -221,9 +239,14 @@ protected IDocument acquireDocument(IProgressMonitor pm) throws CoreException {
IPath path= fFile.getFullPath();
manager.connect(path, LocationKind.IFILE, pm);
fBuffer= manager.getTextFileBuffer(path, LocationKind.IFILE);
IDocument result= fBuffer.getDocument();
fContentStamp= ContentStamps.get(fFile, result);
return result;

if (fBuffer == null || fBuffer.getDocument() == null) {
throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(),
"Failed to acquire document: Buffer or document is null"));
}

fContentStamp = ContentStamps.get(fFile, fBuffer.getDocument());
return fBuffer.getDocument();
}
}

Expand All @@ -244,14 +267,22 @@ protected void commit(IDocument document, IProgressMonitor pm) throws CoreExcept
@Override
protected void releaseDocument(IDocument document, IProgressMonitor pm) throws CoreException {
synchronized (fAcquireCount) { // synchronize with acquireDocument
int acquireCount= fAcquireCount.decrementAndGet();
Assert.isTrue(acquireCount >= 0);
if (acquireCount == 0) {
ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
manager.disconnect(fFile.getFullPath(), LocationKind.IFILE, pm);
try {
int acquireCount = fAcquireCount.decrementAndGet();
Assert.isTrue(acquireCount >= 0);
if (acquireCount == 0) {
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
if (fBuffer != null && fBuffer.getDocument() != null) {
manager.disconnect(fFile.getFullPath(), LocationKind.IFILE, pm);
} else {
System.err.println;
}
}
} catch (AssertionFailedException e) {
System.err.println("Document release assertion failed: " + e.getMessage());
}
}
}
}

@Override
protected final Change createUndoChange(UndoEdit edit) {
Expand Down