Skip to content

Commit e2e37df

Browse files
authored
Merge pull request #8951 from apache/delivery
Sync delivery to master after 28-rc2 (the good one)
2 parents 8e2bc77 + a99e87c commit e2e37df

File tree

9 files changed

+102
-31
lines changed

9 files changed

+102
-31
lines changed

extide/o.apache.tools.ant.module/src/org/apache/tools/ant/module/AntSettings.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.TreeMap;
3232
import java.util.logging.Level;
3333
import java.util.logging.Logger;
34+
import java.util.prefs.BackingStoreException;
3435
import java.util.prefs.Preferences;
3536
import java.util.regex.Pattern;
3637
import org.apache.tools.ant.module.api.IntrospectedInfo;
@@ -122,7 +123,27 @@ public static synchronized IntrospectedInfo getCustomDefs() {
122123
}
123124

124125
public static synchronized void setCustomDefs(IntrospectedInfo ii) {
125-
IntrospectedInfoSerializer.instance.store(prefs().node(PROP_CUSTOM_DEFS), ii);
126+
Preferences prefs = prefs();
127+
Preferences node = prefs.node(PROP_CUSTOM_DEFS);
128+
try {
129+
IntrospectedInfoSerializer.instance.store(node, ii);
130+
} catch (IllegalArgumentException iae) {
131+
// recreate node in case of corrupted files. Once Preferences are loaded,
132+
// keys which contain code point U+0000 can't be used anymore (clear() will also fail)
133+
if (iae.getMessage().contains("U+0000")) {
134+
LOG.log(Level.WARNING, "recreating {0} preferences node due to code point U+0000", PROP_CUSTOM_DEFS);
135+
try {
136+
node.removeNode();
137+
prefs.flush();
138+
node = prefs.node(PROP_CUSTOM_DEFS);
139+
IntrospectedInfoSerializer.instance.store(node, ii);
140+
} catch (BackingStoreException bse) {
141+
throw new RuntimeException("can't write to preferences", bse);
142+
}
143+
} else {
144+
throw iae;
145+
}
146+
}
126147
customDefs = ii;
127148
}
128149

extide/o.apache.tools.ant.module/src/org/apache/tools/ant/module/api/IntrospectedInfo.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -683,21 +683,21 @@ public IntrospectedInfo load(Preferences node) {
683683
try {
684684
v = node.get(k, null);
685685
} catch (IllegalArgumentException ex) { // e.g invalid code point JDK-8075156
686-
LOG.log(Level.WARNING, "malformed key: {0}, pref path: {1}, msg: {2}",
687-
new Object[] {k, node.absolutePath(), ex.getMessage()});
686+
LOG.log(Level.WARNING, "skipping malformed key; pref path: {0}, msg: {1}",
687+
new Object[] {node.absolutePath(), ex.getMessage()});
688688
continue;
689689
}
690690
assert v != null : k;
691691
String[] ss = k.split("\\.", 2);
692692
if (ss.length != 2) {
693-
LOG.log(Level.WARNING, "malformed key: {0}, pref path: {1}", new Object[] {k, node.absolutePath()});
693+
LOG.log(Level.WARNING, "skipping malformed key: {0}, pref path: {1}", new Object[] {k, node.absolutePath()});
694694
continue;
695695
}
696696
if (ss[0].equals("class")) {
697697
Matcher m = p.matcher(ss[1]);
698698
boolean match = m.matches();
699699
if (!match) {
700-
LOG.log(Level.WARNING, "malformed key: {0}, pref path: {1}", new Object[] {k, node.absolutePath()});
700+
LOG.log(Level.WARNING, "skipping malformed key: {0}, pref path: {1}", new Object[] {k, node.absolutePath()});
701701
continue;
702702
}
703703
String c = m.group(1);

ide/git/src/org/netbeans/modules/git/ui/branch/Bundle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ LBL_DeleteBranchAction.progressName=Deleting Branch {0}
3232
LBL_DeleteBranchAction.notMerged=Branch Not Fully Merged
3333
MSG_DeleteBranchAction.notMerged=Branch {0} has not been fully merged yet.\n\
3434
Do you still want to delete the branch?
35+
MSG_DeleteBranchAction.noOtherBranches=Repository does not have any other branches
3536
LBL_DeleteBranchAction.confirmation=Delete Branch
36-
MSG_DeleteBranchAction.confirmation=Do you really want to delete branch {0}
37+
MSG_DeleteBranchAction.confirmation=Do you really want to delete branch {0}?
3738
CreateBranchPanel.cbCheckoutBranch.text=Check&out Created Branch
3839
CreateBranchPanel.cbCheckoutBranch.TTtext=Checkout the branch right after it is created
3940

ide/git/src/org/netbeans/modules/git/ui/branch/DeleteBranchAction.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.netbeans.modules.git.client.GitClientExceptionHandler;
2323
import java.io.File;
2424
import java.util.HashMap;
25-
import java.util.Map;
2625
import java.util.logging.Level;
2726
import java.util.logging.Logger;
2827
import org.netbeans.libs.git.GitBranch;
@@ -38,7 +37,6 @@
3837
import org.openide.NotifyDescriptor;
3938
import org.openide.awt.ActionID;
4039
import org.openide.awt.ActionRegistration;
41-
import org.openide.nodes.Node;
4240
import org.openide.util.NbBundle;
4341

4442
/**
@@ -58,6 +56,9 @@ protected void performAction(File repository, File[] roots, VCSContext context)
5856
branches.remove(info.getActiveBranch().getName());
5957

6058
if (branches.isEmpty()) {
59+
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
60+
NbBundle.getMessage(DeleteBranchAction.class, "MSG_DeleteBranchAction.noOtherBranches")
61+
));
6162
return;
6263
}
6364

@@ -67,23 +68,6 @@ protected void performAction(File repository, File[] roots, VCSContext context)
6768
}
6869
}
6970

70-
@Override
71-
protected boolean enable(Node[] activatedNodes) {
72-
if (!super.enable(activatedNodes)) {
73-
return false;
74-
}
75-
76-
// require 2+ branches
77-
Map.Entry<File, File[]> actionRoots = getActionRoots(getCurrentContext(activatedNodes));
78-
if (actionRoots != null) {
79-
RepositoryInfo info = RepositoryInfo.getInstance(actionRoots.getKey());
80-
81-
return info != null && info.getBranches().size() > 1;
82-
}
83-
84-
return false;
85-
}
86-
8771
public void deleteBranch(final File repository, final String branchName) {
8872
NotifyDescriptor nd = new NotifyDescriptor.Confirmation(NbBundle.getMessage(DeleteBranchAction.class, "MSG_DeleteBranchAction.confirmation", branchName), //NOI18N
8973
NbBundle.getMessage(DeleteBranchAction.class, "LBL_DeleteBranchAction.confirmation"), //NOI18N

ide/git/src/org/netbeans/modules/git/utils/GitUtils.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,8 @@ public static Set<File> getRepositoryRoots (Collection<File> roots) {
417417
}
418418

419419
/**
420-
*
421-
* @param ctx
422-
* @return
420+
* Returns the repository and its roots. May open a selection dialog if
421+
* there is more than one repository in the provided context.
423422
*/
424423
public static HashMap.SimpleImmutableEntry<File, File[]> getActionRoots(VCSContext ctx) {
425424
Set<File> rootsSet = ctx.getRootFiles();

java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/UnusedDetector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ public boolean isDependencies() {
338338
typeElement = info.getElementUtilities().enclosingTypeElement(el);
339339
searchKinds = EnumSet.of(ClassIndex.SearchKind.METHOD_REFERENCES);
340340
}
341-
case ANNOTATION_TYPE, CLASS, ENUM, INTERFACE -> {
341+
case ANNOTATION_TYPE, CLASS, ENUM, RECORD, INTERFACE -> {
342342
List<? extends TypeElement> topLevelElements = info.getTopLevelElements();
343343
if (topLevelElements.size() == 1 && topLevelElements.get(0) == el) {
344344
return false;

java/java.hints/src/org/netbeans/modules/java/hints/errors/CreateElementUtilities.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public final class CreateElementUtilities {
9595

9696
private CreateElementUtilities() {}
9797

98+
// TODO rewrite so that it returns List.of() instead of null. Both states (null and .isEmpty()) are handled interchangeably atm.
9899
public static List<? extends TypeMirror> resolveType(Set<ElementKind> types, CompilationInfo info, TreePath currentPath, Tree unresolved, int offset, TypeMirror[] typeParameterBound, int[] numTypeParameters) {
99100
switch (currentPath.getLeaf().getKind()) {
100101
case METHOD:
@@ -562,8 +563,13 @@ private static List<? extends TypeMirror> computeLambdaReturn(Set<ElementKind> t
562563
return null;
563564
}
564565

566+
List<? extends TypeMirror> resolved = resolveType(types, info, parent.getParentPath(), let, offset, null, null);
567+
if (resolved == null || resolved.isEmpty()) {
568+
return null;
569+
}
570+
565571
List<TypeMirror> result = new ArrayList<>();
566-
for (TypeMirror target : resolveType(types, info, parent.getParentPath(), let, offset, null, null)) {
572+
for (TypeMirror target : resolved) {
567573
if (!org.netbeans.modules.java.hints.errors.Utilities.isValidType(target) ||
568574
target.getKind() != TypeKind.DECLARED) {
569575
continue;

java/java.hints/src/org/netbeans/modules/java/hints/infrastructure/CreatorBasedLazyFixList.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import java.util.List;
2929
import java.util.Map;
3030
import java.util.concurrent.atomic.AtomicBoolean;
31+
import java.util.logging.Level;
32+
import java.util.logging.Logger;
3133
import org.netbeans.api.java.source.CompilationInfo;
3234
import org.netbeans.modules.java.hints.spi.ErrorRule;
3335
import org.netbeans.modules.java.hints.spi.ErrorRule.Data;
@@ -125,7 +127,15 @@ public void compute(CompilationInfo info, AtomicBoolean cancelled) {
125127
data.setData(diagnosticMessage);
126128
}
127129

128-
List<Fix> currentRuleFixes = rule.run(info, diagnosticKey, offset, path, data);
130+
List<Fix> currentRuleFixes;
131+
132+
try {
133+
currentRuleFixes = rule.run(info, diagnosticKey, offset, path, data);
134+
} catch (Exception ex) {
135+
Logger.getLogger(CreatorBasedLazyFixList.class.getName())
136+
.log(Level.WARNING, rule.getDisplayName()+ " rule failed", ex);
137+
continue;
138+
}
129139

130140
if (currentRuleFixes == CANCELLED) {
131141
cancelled.set(true);

java/java.hints/test/unit/src/org/netbeans/modules/java/hints/bugs/UnusedTest.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,54 @@ public void testUnusedNoPackagePrivate() throws Exception {
8585
.run(Unused.class)
8686
.assertWarnings();
8787
}
88+
89+
public void testNoFixForTopLevelPackagePrivateClass() throws Exception {
90+
HintTest.create()
91+
.input(
92+
"""
93+
package test;
94+
class Test {
95+
}
96+
""")
97+
.run(Unused.class)
98+
.assertWarnings();
99+
}
100+
101+
public void testNoFixForTopLevelPackagePrivateEnum() throws Exception {
102+
HintTest.create()
103+
.input(
104+
"""
105+
package test;
106+
enum Test {
107+
}
108+
""")
109+
.run(Unused.class)
110+
.assertWarnings();
111+
}
112+
113+
public void testNoFixForTopLevelPackagePrivateInterface() throws Exception {
114+
HintTest.create()
115+
.input(
116+
"""
117+
package test;
118+
interface Test {
119+
}
120+
""")
121+
.run(Unused.class)
122+
.assertWarnings();
123+
}
124+
125+
public void testNoFixForTopLevelPackagePrivateRecord() throws Exception {
126+
HintTest.create()
127+
.sourceLevel(17)
128+
.input(
129+
"""
130+
package test;
131+
record Test() {
132+
}
133+
""")
134+
.run(Unused.class)
135+
.assertWarnings();
136+
}
137+
88138
}

0 commit comments

Comments
 (0)