Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
import java.util.regex.Pattern;
import org.apache.tools.ant.module.api.IntrospectedInfo;
Expand Down Expand Up @@ -122,7 +123,27 @@ public static synchronized IntrospectedInfo getCustomDefs() {
}

public static synchronized void setCustomDefs(IntrospectedInfo ii) {
IntrospectedInfoSerializer.instance.store(prefs().node(PROP_CUSTOM_DEFS), ii);
Preferences prefs = prefs();
Preferences node = prefs.node(PROP_CUSTOM_DEFS);
try {
IntrospectedInfoSerializer.instance.store(node, ii);
} catch (IllegalArgumentException iae) {
// recreate node in case of corrupted files. Once Preferences are loaded,
// keys which contain code point U+0000 can't be used anymore (clear() will also fail)
if (iae.getMessage().contains("U+0000")) {
LOG.log(Level.WARNING, "recreating {0} preferences node due to code point U+0000", PROP_CUSTOM_DEFS);
try {
node.removeNode();
prefs.flush();
node = prefs.node(PROP_CUSTOM_DEFS);
IntrospectedInfoSerializer.instance.store(node, ii);
} catch (BackingStoreException bse) {
throw new RuntimeException("can't write to preferences", bse);
}
} else {
throw iae;
}
}
customDefs = ii;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,21 +683,21 @@ public IntrospectedInfo load(Preferences node) {
try {
v = node.get(k, null);
} catch (IllegalArgumentException ex) { // e.g invalid code point JDK-8075156
LOG.log(Level.WARNING, "malformed key: {0}, pref path: {1}, msg: {2}",
new Object[] {k, node.absolutePath(), ex.getMessage()});
LOG.log(Level.WARNING, "skipping malformed key; pref path: {0}, msg: {1}",
new Object[] {node.absolutePath(), ex.getMessage()});
continue;
}
assert v != null : k;
String[] ss = k.split("\\.", 2);
if (ss.length != 2) {
LOG.log(Level.WARNING, "malformed key: {0}, pref path: {1}", new Object[] {k, node.absolutePath()});
LOG.log(Level.WARNING, "skipping malformed key: {0}, pref path: {1}", new Object[] {k, node.absolutePath()});
continue;
}
if (ss[0].equals("class")) {
Matcher m = p.matcher(ss[1]);
boolean match = m.matches();
if (!match) {
LOG.log(Level.WARNING, "malformed key: {0}, pref path: {1}", new Object[] {k, node.absolutePath()});
LOG.log(Level.WARNING, "skipping malformed key: {0}, pref path: {1}", new Object[] {k, node.absolutePath()});
continue;
}
String c = m.group(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ LBL_DeleteBranchAction.progressName=Deleting Branch {0}
LBL_DeleteBranchAction.notMerged=Branch Not Fully Merged
MSG_DeleteBranchAction.notMerged=Branch {0} has not been fully merged yet.\n\
Do you still want to delete the branch?
MSG_DeleteBranchAction.noOtherBranches=Repository does not have any other branches
LBL_DeleteBranchAction.confirmation=Delete Branch
MSG_DeleteBranchAction.confirmation=Do you really want to delete branch {0}
MSG_DeleteBranchAction.confirmation=Do you really want to delete branch {0}?
CreateBranchPanel.cbCheckoutBranch.text=Check&out Created Branch
CreateBranchPanel.cbCheckoutBranch.TTtext=Checkout the branch right after it is created

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.netbeans.modules.git.client.GitClientExceptionHandler;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.netbeans.libs.git.GitBranch;
Expand All @@ -38,7 +37,6 @@
import org.openide.NotifyDescriptor;
import org.openide.awt.ActionID;
import org.openide.awt.ActionRegistration;
import org.openide.nodes.Node;
import org.openide.util.NbBundle;

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

if (branches.isEmpty()) {
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
NbBundle.getMessage(DeleteBranchAction.class, "MSG_DeleteBranchAction.noOtherBranches")
));
return;
}

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

@Override
protected boolean enable(Node[] activatedNodes) {
if (!super.enable(activatedNodes)) {
return false;
}

// require 2+ branches
Map.Entry<File, File[]> actionRoots = getActionRoots(getCurrentContext(activatedNodes));
if (actionRoots != null) {
RepositoryInfo info = RepositoryInfo.getInstance(actionRoots.getKey());

return info != null && info.getBranches().size() > 1;
}

return false;
}

public void deleteBranch(final File repository, final String branchName) {
NotifyDescriptor nd = new NotifyDescriptor.Confirmation(NbBundle.getMessage(DeleteBranchAction.class, "MSG_DeleteBranchAction.confirmation", branchName), //NOI18N
NbBundle.getMessage(DeleteBranchAction.class, "LBL_DeleteBranchAction.confirmation"), //NOI18N
Expand Down
5 changes: 2 additions & 3 deletions ide/git/src/org/netbeans/modules/git/utils/GitUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,8 @@ public static Set<File> getRepositoryRoots (Collection<File> roots) {
}

/**
*
* @param ctx
* @return
* Returns the repository and its roots. May open a selection dialog if
* there is more than one repository in the provided context.
*/
public static HashMap.SimpleImmutableEntry<File, File[]> getActionRoots(VCSContext ctx) {
Set<File> rootsSet = ctx.getRootFiles();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public boolean isDependencies() {
typeElement = info.getElementUtilities().enclosingTypeElement(el);
searchKinds = EnumSet.of(ClassIndex.SearchKind.METHOD_REFERENCES);
}
case ANNOTATION_TYPE, CLASS, ENUM, INTERFACE -> {
case ANNOTATION_TYPE, CLASS, ENUM, RECORD, INTERFACE -> {
List<? extends TypeElement> topLevelElements = info.getTopLevelElements();
if (topLevelElements.size() == 1 && topLevelElements.get(0) == el) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public final class CreateElementUtilities {

private CreateElementUtilities() {}

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

List<? extends TypeMirror> resolved = resolveType(types, info, parent.getParentPath(), let, offset, null, null);
if (resolved == null || resolved.isEmpty()) {
return null;
}

List<TypeMirror> result = new ArrayList<>();
for (TypeMirror target : resolveType(types, info, parent.getParentPath(), let, offset, null, null)) {
for (TypeMirror target : resolved) {
if (!org.netbeans.modules.java.hints.errors.Utilities.isValidType(target) ||
target.getKind() != TypeKind.DECLARED) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.netbeans.api.java.source.CompilationInfo;
import org.netbeans.modules.java.hints.spi.ErrorRule;
import org.netbeans.modules.java.hints.spi.ErrorRule.Data;
Expand Down Expand Up @@ -125,7 +127,15 @@ public void compute(CompilationInfo info, AtomicBoolean cancelled) {
data.setData(diagnosticMessage);
}

List<Fix> currentRuleFixes = rule.run(info, diagnosticKey, offset, path, data);
List<Fix> currentRuleFixes;

try {
currentRuleFixes = rule.run(info, diagnosticKey, offset, path, data);
} catch (Exception ex) {
Logger.getLogger(CreatorBasedLazyFixList.class.getName())
.log(Level.WARNING, rule.getDisplayName()+ " rule failed", ex);
continue;
}

if (currentRuleFixes == CANCELLED) {
cancelled.set(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,54 @@ public void testUnusedNoPackagePrivate() throws Exception {
.run(Unused.class)
.assertWarnings();
}

public void testNoFixForTopLevelPackagePrivateClass() throws Exception {
HintTest.create()
.input(
"""
package test;
class Test {
}
""")
.run(Unused.class)
.assertWarnings();
}

public void testNoFixForTopLevelPackagePrivateEnum() throws Exception {
HintTest.create()
.input(
"""
package test;
enum Test {
}
""")
.run(Unused.class)
.assertWarnings();
}

public void testNoFixForTopLevelPackagePrivateInterface() throws Exception {
HintTest.create()
.input(
"""
package test;
interface Test {
}
""")
.run(Unused.class)
.assertWarnings();
}

public void testNoFixForTopLevelPackagePrivateRecord() throws Exception {
HintTest.create()
.sourceLevel(17)
.input(
"""
package test;
record Test() {
}
""")
.run(Unused.class)
.assertWarnings();
}

}
Loading