From 31621dd672805411433cfe1b784e4084dbc690ff Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 30 Mar 2016 17:02:33 +0200 Subject: [PATCH] [ui] fixes "Attach sources" chooser cancellation (IDEA-153651) --- .../impl/AttachSourcesNotificationProvider.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/java/idea-ui/src/com/intellij/codeInsight/daemon/impl/AttachSourcesNotificationProvider.java b/java/idea-ui/src/com/intellij/codeInsight/daemon/impl/AttachSourcesNotificationProvider.java index ebac72fdd5bb..0b930ea93924 100644 --- a/java/idea-ui/src/com/intellij/codeInsight/daemon/impl/AttachSourcesNotificationProvider.java +++ b/java/idea-ui/src/com/intellij/codeInsight/daemon/impl/AttachSourcesNotificationProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -178,10 +178,9 @@ public class AttachSourcesNotificationProvider extends EditorNotifications.Provi @Nullable private static String getClassFileInfo(VirtualFile file) { try { - byte[] data = file.contentsToByteArray(); + byte[] data = file.contentsToByteArray(false); if (data.length > 8) { - DataInputStream stream = new DataInputStream(new ByteArrayInputStream(data)); - try { + try (DataInputStream stream = new DataInputStream(new ByteArrayInputStream(data))) { if (stream.readInt() == 0xCAFEBABE) { int minor = stream.readUnsignedShort(); int major = stream.readUnsignedShort(); @@ -191,9 +190,6 @@ public class AttachSourcesNotificationProvider extends EditorNotifications.Provi return info.toString(); } } - finally { - stream.close(); - } } } catch (IOException ignored) { } @@ -305,10 +301,9 @@ public class AttachSourcesNotificationProvider extends EditorNotifications.Provi Library firstLibrary = libraries.get(0).getLibrary(); VirtualFile[] roots = firstLibrary != null ? firstLibrary.getFiles(OrderRootType.CLASSES) : VirtualFile.EMPTY_ARRAY; VirtualFile[] candidates = FileChooser.chooseFiles(descriptor, myProject, roots.length == 0 ? null : PathUtil.getLocalFile(roots[0])); - final VirtualFile[] files = LibrarySourceRootDetectorUtil.scanAndSelectDetectedJavaSourceRoots(myParentComponent, candidates); - if (files.length == 0) { - return ActionCallback.REJECTED; - } + if (candidates.length == 0) return ActionCallback.REJECTED; + VirtualFile[] files = LibrarySourceRootDetectorUtil.scanAndSelectDetectedJavaSourceRoots(myParentComponent, candidates); + if (files.length == 0) return ActionCallback.REJECTED; final Map librariesToAppendSourcesTo = new HashMap(); for (LibraryOrderEntry library : libraries) {