eclipse-jdt / eclipse.jdt.ui Goto Github PK
View Code? Open in Web Editor NEWLicense: Eclipse Public License 2.0
License: Eclipse Public License 2.0
"Extract Variable" refactoring is a useful feature of JDT. However, in some cases, it may not work correctly. Here we report a bug in this feature and attach a feasible patch for the bug.
We take the following sample code to illustrate the bug:
1 /* CS1: Original Code Snippet */
2 public String metaPhone(final String txt){
3 boolean hard = false;
4 if(txt == null || txt.length() == 0){
5 return "";
6 }
7 if(txt.length() == 1){
8 return txt.toUpperCase(java.util.Local.ENGLISH);
9 }
10 //Do other things
11 // ...
12 }
If we select expression txt.length()
(line 4
in CS1
), conduct refactoring "extract local variable",and name the new variable as length
, we will get the following code snippet:
1 /* CS2: Code Snippet after refactoring */
2 public String metaPhone(final String txt){
3 boolean hard = false;
4 int length = txt.length();
5 if(txt == null || length == 0){
6 return "";
7 }
8 if(length == 1){
9 return txt.toUpperCase(java.util.Local.ENGLISH);
10 }
11 //Do other things
12 // ...
13 }
The refactoring is incorrect and dangerous. If the method is called via metaphone(null)
, the refactored version of the method would result in NullPointerException whereas the original version would not.
The most simple and intuitive solution is to WARN the developers if the refactored version would result in NullPointerException.
First, once developers select an expression and invoke "extract variable" refactoring, we create a list of subexpressions of the selected expression. For example, if we extract expression like a.b.f().c
, the list should contain a
, a.b
, and a.b.f()
. The list is noted as ExpList
.
Second, we analyze the code snippet between the newly introduced local variable declaration (line 4
in CS2
) and the first usage of the variable (line 5
in CS2
). If the code snippet contains InfixExpression node like x==null
, and x
is on ExpList
, we warn the developer with clear information about the potential problem.
Similar error may occur when developers select txt.length()
on other places (i.e., line 7
in CS1
) to conduct "extract variable" refactoring. The refactoring will get the same result as CS2
.
To this end, we apply a greedy strategy to extract as many as expressions without introducing NullPointerException.
EXP
)itself could be extracted safely. If not, we warn the developers.EXP
for expressions identical to EXP
, and validate whether they could be extracted together safely. Resulting in a sequence of instances of the expression, noted as InsExp1
.EXP
for expressions identical to EXP
, and validate whether they could be extracted together. Resulting in a sequence of instances of the expression, noted as InsExp2
.var
and replace all instances in InsExp2
, EXP
, and InsExp2
.The relevant code has been completed and the corresponding PR will be submitted later.
To run source cleanups for multiple projects I have to use the package explorer. Project explorer does only allow this for a select source folder.
Project explorer:
Package Explorer:
Would be really nice to be able to use project explorer for this also, as it is the default view for all perspectives except the JDT one and I only use project explorer because it has features package explorer does not have like hierarchiy view and an easy to reach filter button.
Adding the description from https://bugs.eclipse.org/bugs/show_bug.cgi?id=577317#c0 by @SarikaSinha
I create a "sealed" class C1 without any permits.
This shows compilation error "Sealed class or interface lacks the permits clause and no class or interface from the same compilation unit declares test1 as its direct superclass or superinterface"
But I don't see any corresponding quick fix, it will be good to see 2 quickfixes. One to create class in the same compilation unit and other one to create a child class in the same package.
When completing same code in both VSCodeJava and Eclipse, Eclipse JDT completion popup is slow to be populated compared to VSCode completions. This needs to be investigated and improved to provide same or more better level of response time in JDT.
This could be because of lack of debouncing in the JDT.UI editor for keystrokes.
For the Replace system property with constants cleanup found on the Java Feature cleanups page, change the existing sub-option "Boolean type property" to be "Boxed type property" and include support for Long and Integer. For example:
Integer.parseInt(System.getProperty("Option")); //$NON-NLS-1$
changes to:
Integer.getInteger("Option"); //$NON-NLS-1$
In org.eclipse.jdt.internal.ui.text.java.ChainCompletionProposalComputer.initializeRequiredContext(ContentAssistInvocationContext)
, when the ICompilationUnit
returned by our JavaContentAssistInvocationContext
is null
, then the following NPE happens:
java.lang.NullPointerException
at org.eclipse.jdt.ui.text.java.CompletionProposalCollector.<init>(CompletionProposalCollector.java:150)
at org.eclipse.jdt.internal.ui.text.java.ChainCompletionProposalComputer.initializeRequiredContext(ChainCompletionProposalComputer.java:86)
This seems similar to the old https://bugs.eclipse.org/bugs/show_bug.cgi?id=95862 which was fixed with an early null check.
This was previously posted in the eclipse-platform (eclipse-platform/.github#5) and was requested to be posted to eclipse-jdt/eclipse.jdt.ui as an issue.
Upon recently upgrading to 2022-03 I have noticed that the "Compress all package name segments, except the final segment" is not compressing the packages in my project. I have attempted to use the compression pattern '.', '0', and '1' with no success.
I also attempted to use the "Abbreviate package names" and that was not doing anything to the package names that I specified either.
I have manage to figure out the following since the original post to the eclipse-platform issues:
I deleted the .project file for my project and it displayed properly, however when I converted it back to a faceted project the issue comes back. Please see attached screenshots
map.entrySet().forEach(e| -> {
})
suggest variable names at e|
based on the resolved lambda variable type like any other variable name suggestion.
It looks like the organize imports cleanup is based on very old code that is in parts in jdt.ui and jdt.core. It does not follow the patterns other cleanups are aligned to and beside the broken preview has more issues. In some situations (classpath issue in project) it exchanges your imports with unrelated imports. Maybe the reason is that it uses in some structures just the plain class name that is not unique in all cases (Think of "Path" that is used for classes in eclipse and in java itself).
I'm talking about the upper part of the window where other cleanups show a tree for each code location found.
While testing https://www.eclipse.org/eclipse/news/4.24/jdt.php#junit5-rerun-failures-first
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class t {
@Test
void atest() {
//fail("Not yet implemented");
}
@Test
void test() {
fail("Not yet implemented");
}
}
While running re-run I get
May 17, 2022 10:33:39 PM org.junit.jupiter.engine.config.InstantiatingConfigurationParameterConverter logFailureMessage
WARNING: Failed to load default method orderer class 'org.eclipse.jdt.internal.junit5.runner.FailuresFirstMethodOrderer' set via the 'junit.jupiter.testmethod.order.default' configuration parameter. Falling back to default behavior.
java.lang.ClassNotFoundException: org.eclipse.jdt.internal.junit5.runner.FailuresFirstMethodOrderer
at org.eclipse.pde.internal.junit.runtime.MultiBundleClassLoader.findClass(MultiBundleClassLoader.java:40)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:587)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
at org.junit.platform.commons.util.ReflectionUtils.lambda$tryToLoadClass$9(ReflectionUtils.java:829)
at org.junit.platform.commons.function.Try.lambda$call$0(Try.java:57)
at org.junit.platform.commons.function.Try.of(Try.java:93)
Out of a sudden, Refactor > Rename... of a java class name, field name, method etc. does not work anymore but produces the following Unhandled event loop exception
message in the error log.
java.lang.VerifyError: Bad type on operand stack
Exception Details:
Location:
org/eclipse/jdt/internal/corext/dom/LinkedNodeFinder.findByNode(Lorg/eclipse/jdt/core/dom/ASTNode;Lorg/eclipse/jdt/core/dom/Name;)[Lorg/eclipse/jdt/core/dom/Name; @11: invokestatic
Reason:
Type '[Lorg/eclipse/jdt/core/dom/Name;' (current frame, stack[0]) is not assignable to '[Lorg/eclipse/jdt/core/dom/SimpleName;'
Current Frame:
bci: @11
flags: { }
locals: { 'org/eclipse/jdt/core/dom/ASTNode', 'org/eclipse/jdt/core/dom/Name', '[Lorg/eclipse/jdt/core/dom/Name;' }
stack: { '[Lorg/eclipse/jdt/core/dom/Name;' }
Bytecode:
0000000: 2a2b b801 044d 2cc6 000b 2cb8 016b b801
0000010: 6bb0 2bb6 0106 b600 f63e 1d10 1e9f 000f
0000020: 1d10 0a9f 0009 1d10 12a0 0035 bb00 d059
0000030: b700 d23a 04bb 0109 592b 1904 b701 0b3a
0000040: 052a 1905 b600 d819 0419 04b6 00dc bd01
0000050: 07b6 00df c001 0eb8 016b b801 6bb0 04bd
0000060: 0107 5903 2b53 b801 6bb8 016b b0
Stackmap Table:
append_frame(@18,Object[#270])
append_frame(@44,Integer)
same_frame(@94)
at org.eclipse.jdt.internal.ui.refactoring.reorg.RenameLinkedMode.start(RenameLinkedMode.java:238)
at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.run(RenameJavaElementAction.java:250)
at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.doRun(RenameJavaElementAction.java:190)
at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.run(RenameJavaElementAction.java:162)
at org.eclipse.jdt.ui.actions.RenameAction.run(RenameAction.java:121)
at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:278)
at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:252)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:474)
at org.eclipse.jface.commands.ActionHandler.execute(ActionHandler.java:121)
at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:97)
at jdk.internal.reflect.GeneratedMethodAccessor56.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:58)
at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:317)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:251)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:173)
at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:156)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:488)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:487)
at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:213)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.executeCommand(KeyBindingDispatcher.java:308)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.press(KeyBindingDispatcher.java:580)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.processKeyEvent(KeyBindingDispatcher.java:647)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.filterKeySequenceBindings(KeyBindingDispatcher.java:439)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher$KeyDownFilter.handleEvent(KeyBindingDispatcher.java:96)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1170)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4574)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1524)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1547)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1532)
at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1561)
at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1557)
at org.eclipse.swt.widgets.Canvas.sendKeyEvent(Canvas.java:522)
at org.eclipse.swt.widgets.Composite.keyDown(Composite.java:614)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:6260)
at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
at org.eclipse.swt.widgets.Widget.callSuper(Widget.java:236)
at org.eclipse.swt.widgets.Widget.windowSendEvent(Widget.java:2162)
at org.eclipse.swt.widgets.Shell.windowSendEvent(Shell.java:2487)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:6380)
at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
at org.eclipse.swt.widgets.Display.applicationSendEvent(Display.java:5628)
at org.eclipse.swt.widgets.Display.applicationProc(Display.java:5767)
at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
at org.eclipse.swt.internal.cocoa.NSApplication.sendEvent(NSApplication.java:117)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3938)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1155)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1046)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:155)
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:644)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:551)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:156)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:152)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:136)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:401)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:659)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:596)
at org.eclipse.equinox.launcher.Main.run(Main.java:1467)
eclipse.buildId=4.14.1.202204250734
java.version=11.0.9.1
java.vendor=SAP SE
BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_DE
Framework arguments: -product org.springframework.boot.ide.branding.sts4
JavadoceHover
incorrectly uses \n
instead of the proper System.lineSeparator()
It still mentions bugzilla for bugs.
Cleanup
- File file = null;
- file = new File(homeDir, "eclipse"); //$NON-NLS-1$
+ File file = new File(homeDir, "eclipse");
Quickfix
fBrowseFile.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- chooseFile(fArchiveCombo, new String[] {"*" + ZIP_EXTENSION, "*" + WAR_EXTENSION}); //$NON-NLS-1$ //$NON-NLS-2$
- }
- });
+ fBrowseFile.addSelectionListener(widgetSelectedAdapter(e -> chooseFile(fArchiveCombo, new String[] {"*" + ZIP_EXTENSION, "*" + WAR_EXTENSION})));
LeakTestSuite in org.eclipse.jdt.ui.tests pom.xml file has been disabled as these tests are failing in the jenkins github job
https://ci.eclipse.org/jdt/job/eclipse.jdt.ui-github/job/PR-1/10/
This issue is to track the enabling of LeakTestSuite in org.eclipse.jdt.ui.tests pom.xml file once a fix is provided so these tests pass in the job https://ci.eclipse.org/jdt/job/eclipse.jdt.ui-github
A fix in 4.23 to commonize the filter table logic has a bug that always shows the defaults and doesn't display newly added values.
A fix was made in 4.24 M1 and a number of users are reporting this problem after testing 4.23.
The following method:
void m(List<String> strings,List<String> strings2) {
Collections.reverse(strings);
Iterator it = strings.iterator();
while (it.hasNext()) {
String s = (String)it.next();
Iterator it2 = strings2.iterator();
while (it2.hasNext()) {
String s2 = (String) it2.next();
System.out.println(s2);
}
// this extraneous comment causes an exception to occur
}
System.out.println();
}
Causes an exception to occur when the new while -> enhanced for loop conversion is applied. It only fails if the extraneous comment noted is last line in outer while loop.
Add 19 (BETA)
on the Compiler preferences page and show the corresponding disclaimer when it is selected.
I have one Java file (unfortunately I can't share the file) that breaks a lot of Java editor functionality (hover, refactoring, content assist, go to definition). Everything seems to be caused by class cast exceptions. Here's one stack trace that happens when computing text hover fails:
java.lang.ClassCastException: class org.eclipse.jdt.internal.compiler.ast.LocalDeclaration cannot be cast to class org.eclipse.jdt.internal.compiler.ast.MethodDeclaration (org.eclipse.jdt.internal.compiler.ast.LocalDeclaration and org.eclipse.jdt.internal.compiler.ast.MethodDeclaration are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @6d127783)
at org.eclipse.jdt.internal.compiler.parser.Parser.consumeMethodDeclaration(Parser.java:5255)
at org.eclipse.jdt.internal.codeassist.impl.AssistParser.consumeMethodDeclaration(AssistParser.java:747)
at org.eclipse.jdt.internal.compiler.parser.Parser.consumeRule(Parser.java:7153)
at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:13038)
at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:13293)
at org.eclipse.jdt.internal.codeassist.select.SelectionParser.parse(SelectionParser.java:1666)
at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:13250)
at org.eclipse.jdt.internal.compiler.parser.Parser.dietParse(Parser.java:11636)
at org.eclipse.jdt.internal.codeassist.select.SelectionParser.dietParse(SelectionParser.java:1490)
at org.eclipse.jdt.internal.codeassist.SelectionEngine.select(SelectionEngine.java:994)
at org.eclipse.jdt.internal.core.Openable.codeSelect(Openable.java:167)
at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:389)
at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:382)
at org.eclipse.jdt.internal.ui.text.java.hover.AbstractJavaEditorTextHover.getJavaElementsAt(AbstractJavaEditorTextHover.java:121)
at org.eclipse.jdt.internal.ui.text.java.hover.JavadocHover.internalGetHoverInfo(JavadocHover.java:662)
at org.eclipse.jdt.internal.ui.text.java.hover.JavadocHover.getHoverInfo2(JavadocHover.java:658)
at org.eclipse.jdt.internal.ui.text.java.hover.BestMatchHover.getHoverInfo2(BestMatchHover.java:163)
at org.eclipse.jdt.internal.ui.text.java.hover.BestMatchHover.getHoverInfo2(BestMatchHover.java:130)
at org.eclipse.jdt.internal.ui.text.java.hover.JavaEditorTextHoverProxy.getHoverInfo2(JavaEditorTextHoverProxy.java:89)
at org.eclipse.jface.text.TextViewerHoverManager$1.run(TextViewerHoverManager.java:155)
Session data:
eclipse.buildId=4.23.0.I20220308-0310
java.version=17.0.3
java.vendor=Private Build
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Framework arguments: -product org.eclipse.epp.package.java.product -perspective org.eclipse.jdt.ui.JavaPerspective
Command-line arguments: -os linux -ws gtk -arch x86_64 -product org.eclipse.epp.package.java.product -perspective org.eclipse.jdt.ui.JavaPerspective
This issue is opened on behalf of Bug 572555 - Avoid random failures of SaveParticipantTest
Some tests in org.eclipse.jdt.ui.tests.quickfix.SaveParticipantTest fail randomly.
With Eclipse <= 4.23.0
Then there is a text block and the whole line/textblock/method/whatever is marked and moved (Alt-Arrow Up/Down), then all text content is loosing the indentation.
testSnippet("""
something {
else ;
};
""");
after move:
testSnippet("""
something {
else ;
};
""");
When copy/pasting, the indentation is kept.
reproduce:
=> Mouse icon changes to busy and UI freezes till indexing finished. Impossible to cancel.
Expected: show a cancelable(!) "wait till indexing finished" Dialog
"main" #1 prio=6 os_prio=0 cpu=128937.50ms elapsed=1278.33s tid=0x000001580d59f730 nid=0xe70 runnable [0x0000000f8a8fb000]
java.lang.Thread.State: RUNNABLE
at org.eclipse.swt.internal.win32.OS.WaitMessage(Native Method)
at org.eclipse.swt.widgets.Display.sleep(Display.java:4757)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.block(ModalContext.java:167)
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:368)
at org.eclipse.ui.internal.WorkbenchWindow.lambda$7(WorkbenchWindow.java:2345)
at org.eclipse.ui.internal.WorkbenchWindow$$Lambda$2406/0x0000000802052330.run(Unknown Source)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:74)
at org.eclipse.ui.internal.WorkbenchWindow.run(WorkbenchWindow.java:2343)
at org.eclipse.jdt.internal.ui.typehierarchy.TypeHierarchyLifeCycle.ensureRefreshedTypeHierarchy(TypeHierarchyLifeCycle.java:212)
at org.eclipse.jdt.internal.ui.typehierarchy.TypeHierarchyLifeCycle.ensureRefreshedTypeHierarchy(TypeHierarchyLifeCycle.java:161)
at org.eclipse.jdt.internal.ui.typehierarchy.HierarchyInformationControl.setInput(HierarchyInformationControl.java:275)
at org.eclipse.jface.text.AbstractInformationControlManager.internalShowInformationControl(AbstractInformationControlManager.java:1151)
at org.eclipse.jface.text.AbstractInformationControlManager.presentInformation(AbstractInformationControlManager.java:1120)
at org.eclipse.jface.text.AbstractInformationControlManager.setInformation(AbstractInformationControlManager.java:431)
at org.eclipse.jface.text.information.InformationPresenter.computeInformation(InformationPresenter.java:321)
at org.eclipse.jface.text.AbstractInformationControlManager.doShowInformation(AbstractInformationControlManager.java:1101)
at org.eclipse.jface.text.AbstractInformationControlManager.showInformation(AbstractInformationControlManager.java:1091)
at org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer.doOperation(JavaSourceViewer.java:175)
at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor$AdaptedSourceViewer.doOperation(CompilationUnitEditor.java:206)
at org.eclipse.ui.texteditor.TextOperationAction.lambda$0(TextOperationAction.java:130)
at org.eclipse.ui.texteditor.TextOperationAction$$Lambda$2434/0x0000000801dd5490.run(Unknown Source)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:74)
at org.eclipse.ui.texteditor.TextOperationAction.run(TextOperationAction.java:130)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:474)
at org.eclipse.jface.commands.ActionHandler.execute(ActionHandler.java:121)
at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:97)
at jdk.internal.reflect.GeneratedMethodAccessor342.invoke(Unknown Source)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke([email protected]/DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke([email protected]/Method.java:568)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:58)
at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:317)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:251)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:173)
at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:156)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:488)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:485)
at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:213)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.executeCommand(KeyBindingDispatcher.java:308)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.press(KeyBindingDispatcher.java:580)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.processKeyEvent(KeyBindingDispatcher.java:647)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.filterKeySequenceBindings(KeyBindingDispatcher.java:439)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher$KeyDownFilter.handleEvent(KeyBindingDispatcher.java:96)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1262)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1065)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1090)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1075)
at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1117)
at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1113)
at org.eclipse.swt.widgets.Widget.wmChar(Widget.java:1542)
at org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:4868)
at org.eclipse.swt.widgets.Canvas.WM_CHAR(Canvas.java:345)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4746)
at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:340)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:5026)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(Native Method)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3643)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1155)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1046)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:155)
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:644)
at org.eclipse.ui.internal.Workbench$$Lambda$276/0x0000000800ead0f0.run(Unknown Source)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:551)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:156)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:152)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:136)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:402)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0([email protected]/Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke([email protected]/NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke([email protected]/DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke([email protected]/Method.java:568)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:659)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:596)
at org.eclipse.equinox.launcher.Main.run(Main.java:1467)
This change comments out LeakTestSuite in org.eclipse.jdt.ui.tests pom.xml , as these test are failing in the jenkins github job.
Originally posted by @ktatavarthi in #1 (comment)
The test org.eclipse.jdt.ui.tests.quickfix.AnnotateAssistTest1d8.testAnnotateMethod_TypeParameter2 failed on Mac in the build I20220519-0130, with the below error
at java.base/java.util.Objects.requireNonNull(Objects.java:208)
at java.base/java.util.Arrays$ArrayList.<init>(Arrays.java:4137)
at java.base/java.util.Arrays.asList(Arrays.java:4122)
at org.eclipse.jdt.ui.tests.quickfix.AbstractAnnotateAssistTests.collectAnnotateProposals(AbstractAnnotateAssistTests.java:82)
at org.eclipse.jdt.ui.tests.quickfix.AnnotateAssistTest1d8.testAnnotateMethod_TypeParameter2(AnnotateAssistTest1d8.java:1133)
test results link : I20220519-0130/testresults/html/org.eclipse.jdt.ui.tests_ep424I-unit-mac64-java17_macosx
i clicked on Java Compiler in the properties of a library:
java.lang.ClassCastException: class org.eclipse.core.internal.resources.File cannot be cast to class org.eclipse.core.resources.IProject (org.eclipse.core.internal.resources.File and org.eclipse.core.resources.IProject are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @6cd1a661)
at org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage.setElement(PropertyAndPreferencePage.java:327)
at org.eclipse.jdt.internal.ui.preferences.CompliancePreferencePage.setElement(CompliancePreferencePage.java:168)
at org.eclipse.ui.internal.dialogs.RegistryPageContributor.createPage(RegistryPageContributor.java:145)
at org.eclipse.ui.internal.dialogs.PropertyPageNode.createPage(PropertyPageNode.java:60)
at org.eclipse.jface.preference.PreferenceDialog.createPage(PreferenceDialog.java:1280)
at org.eclipse.ui.internal.dialogs.FilteredPreferenceDialog.createPage(FilteredPreferenceDialog.java:338)
at org.eclipse.jface.preference.PreferenceDialog.showPage(PreferenceDialog.java:1166)
at org.eclipse.ui.internal.dialogs.FilteredPreferenceDialog.showPage(FilteredPreferenceDialog.java:630)
at org.eclipse.jface.preference.PreferenceDialog$5.lambda$0(PreferenceDialog.java:660)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:74)
at org.eclipse.jface.preference.PreferenceDialog$5.selectionChanged(PreferenceDialog.java:657)
at org.eclipse.jface.viewers.StructuredViewer$3.run(StructuredViewer.java:821)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:174)
at org.eclipse.jface.viewers.StructuredViewer.firePostSelectionChanged(StructuredViewer.java:818)
at org.eclipse.jface.viewers.StructuredViewer.handlePostSelect(StructuredViewer.java:1191)
at org.eclipse.swt.events.SelectionListener$1.widgetSelected(SelectionListener.java:84)
at org.eclipse.jface.util.OpenStrategy.firePostSelectionEvent(OpenStrategy.java:284)
at org.eclipse.jface.util.OpenStrategy$1.lambda$1(OpenStrategy.java:438)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:40)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:132)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4043)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3648)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:823)
at org.eclipse.jface.window.Window.open(Window.java:799)
at org.eclipse.ui.dialogs.PropertyDialogAction.run(PropertyDialogAction.java:155)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:474)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:580)
at org.eclipse.jface.action.ActionContributionItem.lambda$4(ActionContributionItem.java:414)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4251)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1066)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4068)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3645)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:823)
at org.eclipse.jface.window.Window.open(Window.java:799)
at org.eclipse.ui.internal.views.log.EventDetailsDialog.open(EventDetailsDialog.java:192)
at org.eclipse.ui.internal.views.log.EventDetailsDialogAction.run(EventDetailsDialogAction.java:102)
at org.eclipse.ui.internal.views.log.LogView.lambda$2(LogView.java:599)
at org.eclipse.jface.viewers.StructuredViewer$1.run(StructuredViewer.java:780)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:174)
at org.eclipse.jface.viewers.StructuredViewer.fireDoubleClick(StructuredViewer.java:777)
at org.eclipse.jface.viewers.AbstractTreeViewer.handleDoubleSelect(AbstractTreeViewer.java:1542)
at org.eclipse.jface.viewers.StructuredViewer$4.widgetDefaultSelected(StructuredViewer.java:1211)
at org.eclipse.jface.util.OpenStrategy.fireDefaultSelectionEvent(OpenStrategy.java:272)
at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java:329)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4251)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1066)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4068)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3645)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1155)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1046)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:155)
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:644)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:551)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:156)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:152)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:136)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:402)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:577)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:659)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:596)
at org.eclipse.equinox.launcher.Main.run(Main.java:1467)
at org.eclipse.equinox.launcher.Main.main(Main.java:1440)
Text in Package Explorer starts rendering correctly, but as I work it gradually becomes bolder and bolder. If I force a re-render by say alt-tabbing back and forth or hovering the text in question, then it will reset to normal font weight, and start over on its journey.
One way I can force it to happen is to open a java file, introduce a compilation error, save it, remove the error, save it, reintroduce it, save, and so on. This may or may not be the only way.
This has been happening for me with Eclipse on Ubuntu for a long time, during which I have upgraded Ubuntu multiple times. Yesterday I was using the snap version of Eclipse on Ubuntu 22.04 which was affected. I decided to upgrade to see if that would solve it, so I installed openjdk17 (I previously had both 8 and 11 installed, and I'm unsure which I was using) and the Eclipse 2022-03 (4.23.0) using the installer from the Eclipse website, making sure to pick jdk17 in the installer. However the issue was still there. I created a new workspace, and a new barebones project within that workspace, and the issue was still there.
This is a picture of what it can look like. Notice that the jre system library is shown in bold.
The following switch statement was not cleaned up:
switch (mode) {
case FALLBACK_TO_DEFAULT:
return DatapointOutOfRangeMode.FALLBACK_TO_DEFAULT;
case TRUNCATE_TO_RANGE:
return DatapointOutOfRangeMode.TRUNCATE_TO_RANGE;
case ACCEPT_ANYWAY:
return DatapointOutOfRangeMode.ACCEPT_ANYWAY;
case NONE:
return DatapointOutOfRangeMode.NONE;
default:
throw new IllegalArgumentException("Unknown enum constant " + mode);
}
Manually cleaned up to:
return switch (mode) {
case FALLBACK_TO_DEFAULT -> DatapointOutOfRangeMode.FALLBACK_TO_DEFAULT;
case TRUNCATE_TO_RANGE -> DatapointOutOfRangeMode.TRUNCATE_TO_RANGE;
case ACCEPT_ANYWAY -> DatapointOutOfRangeMode.ACCEPT_ANYWAY;
case NONE -> DatapointOutOfRangeMode.NONE;
}
Note:
I just saw a very long running Decoration Job.
It was because of the usage of
IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH
in
org.eclipse.jdt.internal.ui.InterfaceIndicatorLabelDecorator.addOverlaysWithSearchEngine(ITypeRoot, String, IDecoration)
I am not sure about the consequences but i guess it will stall all other Decorations till indexer is ready... is that really smart when indexing takes a long time - say minutes?
Selecting the following text block in the Java editor:
String x = """
This is a text block
with an indent
""";
and using CTRL+i causes the line "with an indent" to be moved in line with the previous line which is wrong as indentation in a text block is intentional.
Back port the typos to 4.23
``
ImageDescriptor desc = info.getFeatureImage();
Image featureImage = null;
Button button = new Button(parent, SWT.FLAT | SWT.PUSH);
button.setData(info);
featureImage = desc.createImage();
ends up as
ImageDescriptor desc = info.getFeatureImage();
Button button = new Button(parent, SWT.FLAT | SWT.PUSH);
button.setData(info);
Image featureImage = desc.createImage();;
images.add(featureImage);
I push the PR andl link to it here so that you can see that.
If I use quick fix to add class in same package, the "permits" is not coloured properly. After going back to the file and adding a "enter" applies the colouring.
Debug learnings: Adding breakpoint in Reconciler leads to proper syntax colouring. Looks like the order of invocation of JavaCompositeReconcilingStrategy is impacting this.
2022-03
java.lang.NullPointerException
at org.eclipse.jdt.internal.corext.fix.StringConcatToTextBlockFixCore$StringConcatFinder.visit(StringConcatToTextBlockFixCore.java:93)
at org.eclipse.jdt.core.dom.Assignment.accept0(Assignment.java:299)
at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:3129)
at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:3177)
at org.eclipse.jdt.core.dom.ExpressionStatement.accept0(ExpressionStatement.java:136)
at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:3129)
at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:3200)
at org.eclipse.jdt.core.dom.Block.accept0(Block.java:128)
at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:3129)
at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:3177)
at org.eclipse.jdt.core.dom.MethodDeclaration.accept0(MethodDeclaration.java:677)
at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:3129)
at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:3200)
at org.eclipse.jdt.core.dom.TypeDeclaration.accept0(TypeDeclaration.java:499)
at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:3129)
at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:3200)
at org.eclipse.jdt.core.dom.CompilationUnit.accept0(CompilationUnit.java:258)
at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:3129)
at org.eclipse.jdt.internal.corext.fix.StringConcatToTextBlockFixCore.createCleanUp(StringConcatToTextBlockFixCore.java:234)
Comments can be lost with new Remove overridden assignment with combine statement.
Input:
IParameter parameter = null;
// get the parameter from the command
parameter = command.getParameter(key);
Output
IParameter parameter = command.getParameter(key);
Desired
// get the parameter from the command
IParameter parameter = command.getParameter(key);
To test use cleanup on org.eclipse.core.commands.ParameterizedCommand from platform.ui
beanDefs.asMap().entrySet().forEach(e| -> {});
when completing at this position the template proposals are suggested. Fixing this could improve the completion suggestions on entry key stroke like VSCode java.
The same thing happens for any variable name definition location such as
BeanDefinitionRegistry r|
A normal test with @disabled shows an overlay icon on the lower-left corner.
This is not the case for @ParameterizedTest.
Also the @ParameterizedTest is not counting in the number of tests and skipped tests.
While testing the fix for #106, another issue appeared when applying the clean for converting switch statements to switch expressions in our code. The following code can be used to easily reproduce the issue:
private static boolean isOne (int value) {
switch (value) {
case 1:
// Some comment
return true;
default:
return false;
}
}
The comment is then wrongly merged with true
after the cleanup:
private static boolean isOne (int value) {
return switch (value) {
case 1 -> // Some comment true;
default -> false;
};
}
Follow-up for #34
#34 allows to run source actions from the project explorer which is great. One missing feature is that this is also possible if the set of project contains one or more non Java projects but at least one Java project. This is currently suported by the Package explorer.
To test:
Create three projects, two Java projects, one of type General.
Open Package Explorer, select all projects, right-click -> You see the Source options
Open Project Explorer, select all projects, right-click -> You DO NOT see the Source options
@jjohnstn can you also have a look at this one?
I think this issue might be related to Wayland (in Linux) because I've just started using the Wayland session in Gnome 42 and I've never experienced this problem before: when I Ctrl+click on a type in the editor and the popup for "Open declaration"/"Open implementation" appears, it becomes nearly impossible to select "Open implementation" (the second item) because the popup disappears (most of the time) when you move the mouse to select the menu. And this happens in Fedora, Arch and Ubuntu (latest versions, Gnome 42, all with Wayland session).
The version of Eclipse is 2022-03 (4.23.0)
The classes of IvyDE managed libraries are not exported into a runnable JAR file when a project JRE System Library is JavaSE-17.
git clone [email protected]:haba713/eclipse-ivyde-export-issue.git
src/com.example/Main.java
in the project tree and choose Run as → Java Application. See the output: {"key":"value"}
.$ java -jar eclipse-ivyde-export-issue.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject
at com.example.Main.main(Main.java:8)
Caused by: java.lang.ClassNotFoundException: org.json.JSONObject
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 1 more
The class org.json.JSONObject
and other JSON classes are not included in the JAR file even though the library is listed in the Ivy dependencies.
Add OpenJDK 8 to Eclipse and change Java Build Path → Libraries → JRE System Library to JavaSE-1.8. After that
the IvyDE managed libraries are included in the runnable JAR file when it's generated again.
See this commit.
The issue was also reported here because I'm not sure if this is a JDT or IvyDE issue.
The guarded pattern in Java 19 3rd preview uses the restricted keyword when
. This has to colored, as all restricted keywords are colored.
Having a class like this:
@Transactional
@RestController("check/health")
public class ServerHealthIcons {
/**
* The entitymanager to use, never <code>null</code>.
*/
@PersistenceContext
private final EntityManager entityManager = null;
@GetMapping("bad/{shcid}.png")
public void bad(@PathVariable long shcid, HttpServletRequest request, HttpServletResponse response)
throws IOException {
ServerHealthCheck shc = entityManager.find(ServerHealthCheck.class, shcid);
byte[] iconPng = shc.getBadIconPng();
response.setContentLength(iconPng.length);
response.setContentType("image/png");
ServletOutputStream out = response.getOutputStream();
out.write(iconPng);
out.close();
}
@GetMapping("warn/{shcid}.png")
public void warn(@PathVariable long shcid, HttpServletRequest request, HttpServletResponse response)
throws IOException {
ServerHealthCheck shc = entityManager.find(ServerHealthCheck.class, shcid);
byte[] iconPng = shc.getBadIconPng();
response.setContentLength(iconPng.length);
response.setContentType("image/png");
ServletOutputStream out = response.getOutputStream();
out.write(iconPng);
out.close();
}
@GetMapping("good/{shcid}.png")
public void good(@PathVariable long shcid, HttpServletRequest request, HttpServletResponse response)
throws IOException {
ServerHealthCheck shc = entityManager.find(ServerHealthCheck.class, shcid);
byte[] iconPng = shc.getGoodIconPng();
response.setContentLength(iconPng.length);
response.setContentType("image/png");
ServletOutputStream out = response.getOutputStream();
out.write(iconPng);
out.close();
}
}
We have about 3 times the mostly exact same method body.
The only difference is the initialization of the iconPng-variable. So we have to extract the iconPng initialization first.
Unfortunately we can only extract as
What I miss here is the possibility to extract the variable to a lamda-function.
The extraction should only be available for one input and one output (two input for BiFunction if you like, consumer, supplier respectievly).
This should the extraction create:
This Line:
byte[] iconPng = shc.getBadIconPng();
Should be extracted to this line:
Function<ServerHealthCheck, byte[]> supply = ServerHealthCheck::getBadIconPng;
byte[] iconPng = supply.apply(shc);
As soon as the FR is implemented, it will be an ease to transform the code above to this:
@Transactional
@RestController("check/health")
public class ServerHealthIcons {
/**
* The entitymanager to use, never <code>null</code>.
*/
@PersistenceContext
private final EntityManager entityManager = null;
@GetMapping("bad/{shcid}.png")
public void bad(@PathVariable long shcid, HttpServletRequest request, HttpServletResponse response)
throws IOException {
extracted(shcid, response, ServerHealthCheck::getBadIconPng);
}
@GetMapping("warn/{shcid}.png")
public void warn(@PathVariable long shcid, HttpServletRequest request, HttpServletResponse response)
throws IOException {
extracted(shcid, response, ServerHealthCheck::getWarningIconPng);
}
@GetMapping("good/{shcid}.png")
public void good(@PathVariable long shcid, HttpServletRequest request, HttpServletResponse response)
throws IOException {
extracted(shcid, response, ServerHealthCheck::getGoodIconPng);
}
private void extracted(long shcid, HttpServletResponse response, Function<ServerHealthCheck, byte[]> supply)
throws IOException {
ServerHealthCheck shc = entityManager.find(ServerHealthCheck.class, shcid);
byte[] iconPng = supply.apply(shc);
response.setContentLength(iconPng.length);
response.setContentType("image/png");
ServletOutputStream out = response.getOutputStream();
out.write(iconPng);
out.close();
}
}
Thanks.
This is an issue tracking Bug 562654 - Intermittent test failures in I-builds : testHierarchicalJUnit, testFormatChanges02, markImplementOccurrences3
The below tests fail randomly in the nightly builds
Created the below issue for random failure of org.eclipse.jdt.ui.tests.quickfix.SaveParticipantTest.testFormatChanges02
If I try to use @suite from latest JUnit Jupiter the context menu to run tests is not available.
See https://howtodoinjava.com/junit5/junit5-test-suites-examples/
To test:
With Java now going more in the direction of Records and traditional Java Beans not as popular I have been seeing more desire to make accessor methods that do not follow the traditional get/set prefix.
Currently you can configure getter/setter body and comment style but you cannot configure the method names.
For example if I have a class like:
public SomeClass {
private String name;
}
I would like to generate accessors just like a Record where there is no get or set:
public SomeClass {
private String name;
public String name() { return this.name; }
public void name(String name) { this.name = name; }
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.