Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Source ranges and buffer out of sync (Javamodel)
Source ranges and buffer out of sync (Javamodel) [message #553604] Wed, 18 August 2010 07:44 Go to next message
Carsten Pfeiffer is currently offline Carsten PfeifferFriend
Messages: 34
Registered: July 2009
Member
Hi,

we're using JDT to read and manipulate Java source files, sometimes from
different threads.

Once in a while it happens that source ranges of an IType do not match its
underlying IBuffer. See this snippet:

IOpenable tempOpenable = aType.getOpenable();
IBuffer tempBuffer = tempOpenable.getBuffer();
int tempSourceOffset = aType.getSourceRange().getOffset();
ISourceRange tempNameRange = aType.getNameRange();
String tempComment = tempBuffer.getText(
tempSourceOffset,
tempNameRange.getOffset() - tempSourceOffset +
tempNameRange.getLength());

The contents of tempComment is sometimes just plain wrong. I am quite sure
that the contents of the compilation unit is *not* modified at the same time
as the above code is being executed. The above code is executed *after* the
modification happened (in a different thread).

[Un]fortunately this is rarely reproduceable. Any ideas where we could start
debugging this or how we could make sure that the buffer and the source
ranges are consistent?

Thanks,
Carsten
Re: Source ranges and buffer out of sync (Javamodel) [message #553630 is a reply to message #553604] Wed, 18 August 2010 08:53 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Carsten Pfeiffer wrote:
> Hi,
>
> we're using JDT to read and manipulate Java source files, sometimes from
> different threads.
>
> Once in a while it happens that source ranges of an IType do not match its
> underlying IBuffer. See this snippet:
>
> IOpenable tempOpenable = aType.getOpenable();
> IBuffer tempBuffer = tempOpenable.getBuffer();
> int tempSourceOffset = aType.getSourceRange().getOffset();
> ISourceRange tempNameRange = aType.getNameRange();
> String tempComment = tempBuffer.getText(
> tempSourceOffset,
> tempNameRange.getOffset() - tempSourceOffset +
> tempNameRange.getLength());
>
> The contents of tempComment is sometimes just plain wrong. I am quite sure
> that the contents of the compilation unit is *not* modified at the same time
> as the above code is being executed. The above code is executed *after* the
> modification happened (in a different thread).
>
> [Un]fortunately this is rarely reproduceable. Any ideas where we could start
> debugging this or how we could make sure that the buffer and the source
> ranges are consistent?
>
See org.eclipse.jdt.core.ICompilationUnit.reconcile(*).

Dani
> Thanks,
> Carsten
>
Re: Source ranges and buffer out of sync (Javamodel) [message #553681 is a reply to message #553630] Wed, 18 August 2010 13:28 Go to previous message
Carsten Pfeiffer is currently offline Carsten PfeifferFriend
Messages: 34
Registered: July 2009
Member
Daniel Megert wrote:

> See org.eclipse.jdt.core.ICompilationUnit.reconcile(*).

We actually have this code after manipulating the compilation units:

try {
aCompilationUnit.discardWorkingCopy();
} finally {
if (aCompilationUnit.isWorkingCopy()) {
aCompilationUnit.reconcile(ICompilationUnit.NO_AST,
false, null, null);
} else {
aCompilationUnit.makeConsistent(null);
}
}

But when we encounter the problem, IOpenable#isConsistent() actually returns
false.

Thanks,
Carsten
Previous Topic:SWT add-on to Eclipse
Next Topic:loaderClass for jsps and eclipse launcher config
Goto Forum:
  


Current Time: Fri Apr 19 04:21:02 GMT 2024

Powered by FUDForum. Page generated in 0.01977 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top