Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
ProjectUtilities
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software Control System
Libraries
java
ProjectUtilities
Commits
e28b1b7d
Commit
e28b1b7d
authored
9 months ago
by
Raphael GIRARDOT
Browse files
Options
Downloads
Patches
Plain Diff
No more printStackTrace() (CONTROLGUI-398)
parent
afbfbcb7
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ApplicationUtilities/src/main/java/fr/soleil/lib/project/application/user/manager/AccountManager.java
+38
-43
38 additions, 43 deletions
.../lib/project/application/user/manager/AccountManager.java
with
38 additions
and
43 deletions
ApplicationUtilities/src/main/java/fr/soleil/lib/project/application/user/manager/AccountManager.java
+
38
−
43
View file @
e28b1b7d
...
...
@@ -28,6 +28,8 @@ import java.util.Map;
import
javax.swing.Icon
;
import
javax.swing.ImageIcon
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.w3c.dom.Node
;
import
org.w3c.dom.NodeList
;
...
...
@@ -124,6 +126,8 @@ public class AccountManager implements IAccountSelectionListener {
public
static
final
Color
ACCOUNT_COLOR
=
new
Color
(
192
,
192
,
255
);
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
AccountManager
.
class
);
private
static
final
long
TIME_TO_WAIT
=
10000
;
private
static
final
long
MAX_TIME_TO_WAIT
=
50000
;
...
...
@@ -260,7 +264,7 @@ public class AccountManager implements IAccountSelectionListener {
}
boolean
accountFileCreated
=
accountFile
.
createNewFile
();
if
(!
accountFileCreated
)
{
showFailedMessage
(
CREATION_FAILED
);
showFailedMessage
(
CREATION_FAILED
,
null
);
result
=
CREATION_FAILED
;
}
XMLLine
emptyLine
=
new
XMLLine
(
mainNodeTag
,
XMLLine
.
EMPTY_TAG_CATEGORY
);
...
...
@@ -268,19 +272,17 @@ public class AccountManager implements IAccountSelectionListener {
try
{
lockFile
.
delete
();
}
catch
(
SecurityException
security
)
{
showFailedMessage
(
REMOVE_LOCK_FAILED
);
showFailedMessage
(
REMOVE_LOCK_FAILED
,
security
);
result
=
REMOVE_LOCK_FAILED
;
}
}
catch
(
SecurityException
security
)
{
showFailedMessage
(
CREATION_FAILED
);
showFailedMessage
(
CREATION_FAILED
,
security
);
result
=
CREATION_FAILED
;
}
catch
(
IOException
io
)
{
io
.
printStackTrace
();
showFailedMessage
(
WRITE_FAILED
);
showFailedMessage
(
WRITE_FAILED
,
io
);
result
=
WRITE_FAILED
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
showFailedMessage
(
UNKNOWN
);
showFailedMessage
(
UNKNOWN
,
e
);
result
=
UNKNOWN
;
}
}
...
...
@@ -318,8 +320,7 @@ public class AccountManager implements IAccountSelectionListener {
result
=
0
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
showFailedMessage
(
UNKNOWN
);
showFailedMessage
(
UNKNOWN
,
e
);
result
=
UNKNOWN
;
}
finally
{
// Loading successful
...
...
@@ -340,7 +341,7 @@ public class AccountManager implements IAccountSelectionListener {
int
reload
=
this
.
loadAccounts
();
long
time
=
System
.
currentTimeMillis
();
while
((!
lockFile
.
createNewFile
())
&&
(
System
.
currentTimeMillis
()
<
time
+
MAX_TIME_TO_WAIT
))
{
showFailedMessage
(
USED_FAILED
);
showFailedMessage
(
USED_FAILED
,
null
);
Thread
.
sleep
(
TIME_TO_WAIT
);
}
if
(
System
.
currentTimeMillis
()
>=
time
+
MAX_TIME_TO_WAIT
)
{
...
...
@@ -368,7 +369,7 @@ public class AccountManager implements IAccountSelectionListener {
try
{
lockFile
.
delete
();
}
catch
(
SecurityException
security
)
{
showFailedMessage
(
REMOVE_LOCK_FAILED
);
showFailedMessage
(
REMOVE_LOCK_FAILED
,
security
);
result
=
REMOVE_LOCK_FAILED
;
break
;
}
...
...
@@ -378,27 +379,25 @@ public class AccountManager implements IAccountSelectionListener {
case
USED_FAILED:
// file locked : try again later
showFailedMessage
(
USED_FAILED
);
showFailedMessage
(
USED_FAILED
,
null
);
result
=
USED_FAILED
;
break
;
default
:
// any other exception: this was not expected, exit
showFailedMessage
(
UNKNOWN
);
showFailedMessage
(
UNKNOWN
,
null
);
result
=
UNKNOWN
;
break
;
}
}
catch
(
SecurityException
security
)
{
showFailedMessage
(
USED_FAILED
);
showFailedMessage
(
USED_FAILED
,
security
);
result
=
USED_FAILED
;
}
catch
(
IOException
io
)
{
io
.
printStackTrace
();
showFailedMessage
(
WRITE_FAILED
);
showFailedMessage
(
WRITE_FAILED
,
io
);
result
=
WRITE_FAILED
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
showFailedMessage
(
UNKNOWN
);
showFailedMessage
(
UNKNOWN
,
e
);
result
=
UNKNOWN
;
}
finally
{
if
((
result
!=
NAME_ALREADY_EXISTS
)
&&
(
result
!=
PATH_ALREADY_EXISTS
))
{
...
...
@@ -421,7 +420,7 @@ public class AccountManager implements IAccountSelectionListener {
try
{
long
time
=
System
.
currentTimeMillis
();
while
((!
lockFile
.
createNewFile
())
&&
(
System
.
currentTimeMillis
()
<
time
+
MAX_TIME_TO_WAIT
))
{
showFailedMessage
(
USED_FAILED
);
showFailedMessage
(
USED_FAILED
,
null
);
Thread
.
sleep
(
TIME_TO_WAIT
);
}
if
(
System
.
currentTimeMillis
()
>=
time
+
MAX_TIME_TO_WAIT
)
{
...
...
@@ -439,7 +438,7 @@ public class AccountManager implements IAccountSelectionListener {
try
{
lockFile
.
delete
();
}
catch
(
SecurityException
security
)
{
showFailedMessage
(
REMOVE_LOCK_FAILED
);
showFailedMessage
(
REMOVE_LOCK_FAILED
,
security
);
result
=
REMOVE_LOCK_FAILED
;
}
result
=
accountId
;
...
...
@@ -448,26 +447,24 @@ public class AccountManager implements IAccountSelectionListener {
// file locked : try again later
case
USED_FAILED:
showFailedMessage
(
USED_FAILED
);
showFailedMessage
(
USED_FAILED
,
null
);
result
=
USED_FAILED
;
break
;
// any other exception : this was not expected
default
:
showFailedMessage
(
UNKNOWN
);
showFailedMessage
(
UNKNOWN
,
null
);
result
=
UNKNOWN
;
}
}
catch
(
SecurityException
security
)
{
result
=
USED_FAILED
;
showFailedMessage
(
USED_FAILED
);
showFailedMessage
(
USED_FAILED
,
security
);
}
catch
(
IOException
io
)
{
io
.
printStackTrace
();
showFailedMessage
(
WRITE_FAILED
);
showFailedMessage
(
WRITE_FAILED
,
io
);
result
=
WRITE_FAILED
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
showFailedMessage
(
UNKNOWN
);
showFailedMessage
(
UNKNOWN
,
e
);
result
=
UNKNOWN
;
}
finally
{
refreshUIAndClearListLock
();
...
...
@@ -560,44 +557,42 @@ public class AccountManager implements IAccountSelectionListener {
return
name
;
}
private
void
showFailedMessage
(
int
failureType
)
{
private
void
showFailedMessage
(
int
failureType
,
Throwable
error
)
{
String
title
=
getMessage
(
"user.manager.Account.Error.Title"
);
String
message
=
ObjectUtils
.
EMPTY_STRING
;
switch
(
failureType
)
{
case
CREATION_FAILED:
message
=
getMessage
(
"user.manager.Account.Error.File.Creation"
);
break
;
case
WRITE_FAILED:
message
=
getMessage
(
"user.manager.Account.Error.File.Write"
);
break
;
case
READ_FAILED:
message
=
getMessage
(
"user.manager.Account.Error.File.Read"
);
break
;
case
USED_FAILED:
message
=
getMessage
(
"user.manager.Account.Error.File.Used"
);
break
;
case
LOCK_FAILED:
message
=
getMessage
(
"user.manager.Account.Error.File.Lock"
);
break
;
case
LOCK_FOLDER_FAILED:
message
=
getMessage
(
"user.manager.Account.Error.File.Lock.Definitive"
);
break
;
case
REMOVE_LOCK_FAILED:
message
=
getMessage
(
"user.manager.Account.Error.File.Lock.Remove"
);
break
;
case
ACCOUNT_ACCES_DATE_UPDATE_FAILED:
message
=
getMessage
(
"user.manager.Account.Error.AccessDate.Write"
);
break
;
default
:
message
=
getMessage
(
"user.manager.Account.Error.Default"
);
break
;
}
if
(
error
==
null
)
{
LOGGER
.
error
(
message
);
}
else
{
LOGGER
.
error
(
message
,
error
);
}
errorDialog
=
new
DefaultUserManagementErrorDialog
(
accountSelectionFrame
,
title
,
message
);
errorDialog
.
setLocationRelativeTo
(
accountSelectionFrame
);
...
...
@@ -680,11 +675,11 @@ public class AccountManager implements IAccountSelectionListener {
try
{
saveAccounts
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
showFailedMessage
(
ACCOUNT_ACCES_DATE_UPDATE_FAILED
);
showFailedMessage
(
ACCOUNT_ACCES_DATE_UPDATE_FAILED
,
e
);
}
path
=
account
.
getPath
();
File
lockFile
=
new
File
(
path
+
File
.
separator
+
LOCK_FILE_NAME
);
IOException
io
=
null
;
try
{
File
directory
=
new
File
(
path
);
if
(!
directory
.
exists
())
{
...
...
@@ -697,12 +692,12 @@ public class AccountManager implements IAccountSelectionListener {
withError
=
false
;
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
()
;
io
=
e
;
created
=
false
;
withError
=
true
;
}
if
(
withError
)
{
showFailedMessage
(
LOCK_FOLDER_FAILED
);
showFailedMessage
(
LOCK_FOLDER_FAILED
,
io
);
}
else
{
if
(!
created
)
{
if
(
manageMultiSession
&&
accountSelectionFrame
.
getSelectionPanel
().
isMultiSession
())
{
...
...
@@ -744,7 +739,7 @@ public class AccountManager implements IAccountSelectionListener {
}
}
catch
(
IOException
e
)
{
// continue
e
.
printStackTrace
(
);
LOGGER
.
error
(
"Failed to create "
+
lockFile
.
getPath
(),
e
);
lockFile
=
new
File
(
lockFile
.
getParent
());
}
sessionPath
=
null
;
...
...
@@ -766,7 +761,7 @@ public class AccountManager implements IAccountSelectionListener {
try
{
lockFile
.
createNewFile
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
(
);
LOGGER
.
error
(
"Failed to create "
+
lockFile
.
getPath
(),
e
);
}
}
else
{
path
=
null
;
...
...
@@ -826,7 +821,7 @@ public class AccountManager implements IAccountSelectionListener {
try
{
lock
.
delete
();
}
catch
(
SecurityException
e
)
{
e
.
printStackTrace
(
);
LOGGER
.
error
(
"Failed to clear "
+
lock
.
getPath
(),
e
);
cleared
=
false
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment