Bug 566639 - Make Linux libsecret integration work for all archs

Use StandardCharsets to cleanup the code a bit.
Enable more save actions and warnings.

Change-Id: I1ced742cf0106d731861e01b030d940178e9f62c
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/bundles/org.eclipse.equinox.security.linux/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.equinox.security.linux/.settings/org.eclipse.jdt.core.prefs
index a9cd963..d478af2 100644
--- a/bundles/org.eclipse.equinox.security.linux/.settings/org.eclipse.jdt.core.prefs
+++ b/bundles/org.eclipse.equinox.security.linux/.settings/org.eclipse.jdt.core.prefs
@@ -17,6 +17,7 @@
 org.eclipse.jdt.core.compiler.debug.localVariable=generate
 org.eclipse.jdt.core.compiler.debug.sourceFile=generate
 org.eclipse.jdt.core.compiler.problem.APILeak=warning
+org.eclipse.jdt.core.compiler.problem.annotatedTypeArgumentToUnannotated=info
 org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
 org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
@@ -53,7 +54,7 @@
 org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
 org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
 org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
-org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=warning
 org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
 org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning
 org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
@@ -78,6 +79,7 @@
 org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
 org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
 org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed=info
 org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled
 org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
 org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning
@@ -93,6 +95,7 @@
 org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
 org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
 org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning
 org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
 org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
 org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
diff --git a/bundles/org.eclipse.equinox.security.linux/.settings/org.eclipse.jdt.ui.prefs b/bundles/org.eclipse.equinox.security.linux/.settings/org.eclipse.jdt.ui.prefs
new file mode 100644
index 0000000..6b0b13e
--- /dev/null
+++ b/bundles/org.eclipse.equinox.security.linux/.settings/org.eclipse.jdt.ui.prefs
@@ -0,0 +1,109 @@
+eclipse.preferences.version=1
+editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
+sp_cleanup.add_all=false
+sp_cleanup.add_default_serial_version_id=true
+sp_cleanup.add_generated_serial_version_id=false
+sp_cleanup.add_missing_annotations=true
+sp_cleanup.add_missing_deprecated_annotations=true
+sp_cleanup.add_missing_methods=false
+sp_cleanup.add_missing_nls_tags=false
+sp_cleanup.add_missing_override_annotations=true
+sp_cleanup.add_missing_override_annotations_interface_methods=true
+sp_cleanup.add_serial_version_id=false
+sp_cleanup.always_use_blocks=true
+sp_cleanup.always_use_parentheses_in_expressions=false
+sp_cleanup.always_use_this_for_non_static_field_access=false
+sp_cleanup.always_use_this_for_non_static_method_access=false
+sp_cleanup.arrays_fill=false
+sp_cleanup.bitwise_conditional_expression=false
+sp_cleanup.boolean_literal=false
+sp_cleanup.break_loop=false
+sp_cleanup.collection_cloning=false
+sp_cleanup.comparison_statement=false
+sp_cleanup.controlflow_merge=false
+sp_cleanup.convert_functional_interfaces=false
+sp_cleanup.convert_to_enhanced_for_loop=false
+sp_cleanup.convert_to_enhanced_for_loop_if_loop_var_used=false
+sp_cleanup.convert_to_switch_expressions=false
+sp_cleanup.correct_indentation=false
+sp_cleanup.double_negation=false
+sp_cleanup.else_if=false
+sp_cleanup.embedded_if=false
+sp_cleanup.evaluate_nullable=false
+sp_cleanup.extract_increment=false
+sp_cleanup.format_source_code=true
+sp_cleanup.format_source_code_changes_only=false
+sp_cleanup.hash=false
+sp_cleanup.if_condition=false
+sp_cleanup.insert_inferred_type_arguments=false
+sp_cleanup.instanceof=false
+sp_cleanup.join=false
+sp_cleanup.lazy_logical_operator=false
+sp_cleanup.make_local_variable_final=true
+sp_cleanup.make_parameters_final=false
+sp_cleanup.make_private_fields_final=true
+sp_cleanup.make_type_abstract_if_missing_method=false
+sp_cleanup.make_variable_declarations_final=false
+sp_cleanup.map_cloning=false
+sp_cleanup.merge_conditional_blocks=false
+sp_cleanup.multi_catch=false
+sp_cleanup.never_use_blocks=false
+sp_cleanup.never_use_parentheses_in_expressions=true
+sp_cleanup.no_string_creation=false
+sp_cleanup.no_super=false
+sp_cleanup.number_suffix=false
+sp_cleanup.objects_equals=false
+sp_cleanup.on_save_use_additional_actions=true
+sp_cleanup.organize_imports=true
+sp_cleanup.overridden_assignment=false
+sp_cleanup.precompile_regex=false
+sp_cleanup.primitive_parsing=false
+sp_cleanup.primitive_serialization=false
+sp_cleanup.pull_up_assignment=false
+sp_cleanup.push_down_negation=false
+sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
+sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
+sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
+sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
+sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
+sp_cleanup.redundant_falling_through_block_end=false
+sp_cleanup.remove_private_constructors=true
+sp_cleanup.remove_redundant_modifiers=false
+sp_cleanup.remove_redundant_semicolons=true
+sp_cleanup.remove_redundant_type_arguments=false
+sp_cleanup.remove_trailing_whitespaces=true
+sp_cleanup.remove_trailing_whitespaces_all=true
+sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
+sp_cleanup.remove_unnecessary_array_creation=true
+sp_cleanup.remove_unnecessary_casts=true
+sp_cleanup.remove_unnecessary_nls_tags=true
+sp_cleanup.remove_unused_imports=true
+sp_cleanup.remove_unused_local_variables=false
+sp_cleanup.remove_unused_private_fields=true
+sp_cleanup.remove_unused_private_members=false
+sp_cleanup.remove_unused_private_methods=true
+sp_cleanup.remove_unused_private_types=true
+sp_cleanup.simplify_lambda_expression_and_method_ref=true
+sp_cleanup.sort_members=false
+sp_cleanup.sort_members_all=false
+sp_cleanup.static_inner_class=false
+sp_cleanup.strictly_equal_or_different=false
+sp_cleanup.stringbuilder=false
+sp_cleanup.switch=false
+sp_cleanup.ternary_operator=false
+sp_cleanup.try_with_resource=false
+sp_cleanup.use_anonymous_class_creation=false
+sp_cleanup.use_autoboxing=false
+sp_cleanup.use_blocks=false
+sp_cleanup.use_blocks_only_for_return_and_throw=false
+sp_cleanup.use_directly_map_method=false
+sp_cleanup.use_lambda=true
+sp_cleanup.use_parentheses_in_expressions=false
+sp_cleanup.use_this_for_non_static_field_access=false
+sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
+sp_cleanup.use_this_for_non_static_method_access=false
+sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
+sp_cleanup.use_unboxing=false
+sp_cleanup.use_var=false
+sp_cleanup.useless_continue=false
+sp_cleanup.useless_return=false
diff --git a/bundles/org.eclipse.equinox.security.linux/src/org/eclipse/equinox/internal/security/linux/LinuxPasswordProvider.java b/bundles/org.eclipse.equinox.security.linux/src/org/eclipse/equinox/internal/security/linux/LinuxPasswordProvider.java
index 4444eea..2332699 100644
--- a/bundles/org.eclipse.equinox.security.linux/src/org/eclipse/equinox/internal/security/linux/LinuxPasswordProvider.java
+++ b/bundles/org.eclipse.equinox.security.linux/src/org/eclipse/equinox/internal/security/linux/LinuxPasswordProvider.java
@@ -7,7 +7,7 @@
  * https://www.eclipse.org/legal/epl-2.0/
  *
  * SPDX-License-Identifier: EPL-2.0
- * 
+ *
  * Contributors:
  *     Julien HENRY - Linux implementation
  *     Red Hat Inc. - add validation method to handle KDE failures
@@ -15,7 +15,7 @@
  *******************************************************************************/
 package org.eclipse.equinox.internal.security.linux;
 
-import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
 import java.security.SecureRandom;
 
 import javax.crypto.spec.PBEKeySpec;
@@ -40,25 +40,25 @@
 	private static final int PASSWORD_LENGTH = 64;
 
 	private static final String SECRET_COLLECTION_DEFAULT = "default"; //$NON-NLS-1$
-	
+
 	private SecretSchema fEquinoxSchema;
 	private LibSecret fLibSecret;
 	private LibGio fLibGio;
-	
+
 	public LinuxPasswordProvider() {
 		initEquinoxSchema();
 	}
 
 	private void initEquinoxSchema() {
 		fEquinoxSchema = new SecretSchema("org.eclipse.equinox", //$NON-NLS-1$
-				SecretSchemaFlags.SECRET_SCHEMA_NONE, 
-				new SecretSchemaAttribute(null, 0));
+				SecretSchemaFlags.SECRET_SCHEMA_NONE, new SecretSchemaAttribute(null, 0));
 	}
 
 	private interface LibGio extends Library {
 		Pointer g_bus_get_sync(int bus_type, Pointer cancellable, PointerByReference gerror);
 
 		void g_error_free(Pointer error);
+
 		GList.ByReference g_list_append(GList list, Pointer data);
 	}
 
@@ -96,7 +96,7 @@
 			throw new SecurityException(message);
 		}
 
-		fLibSecret = Native.loadLibrary("secret-1", LibSecret.class);
+		fLibSecret = Native.loadLibrary("secret-1", LibSecret.class); //$NON-NLS-1$
 		Pointer secretService = fLibSecret.secret_service_get_sync(SecretServiceFlags.SECRET_SERVICE_LOAD_COLLECTIONS,
 				Pointer.NULL, gerror);
 		if (gerror.getValue() != Pointer.NULL) {
@@ -106,8 +106,8 @@
 			throw new SecurityException(message);
 		}
 
-		Pointer defaultCollection = fLibSecret.secret_collection_for_alias_sync(secretService, SECRET_COLLECTION_DEFAULT,
-				SecretCollectionFlags.SECRET_COLLECTION_NONE, Pointer.NULL, gerror);
+		Pointer defaultCollection = fLibSecret.secret_collection_for_alias_sync(secretService,
+				SECRET_COLLECTION_DEFAULT, SecretCollectionFlags.SECRET_COLLECTION_NONE, Pointer.NULL, gerror);
 		if (gerror.getValue() != Pointer.NULL) {
 			GError error = new GError(gerror.getValue());
 			String message = "Unable to get secret collection: " + error.message; //$NON-NLS-1$
@@ -158,12 +158,8 @@
 			throw new SecurityException("Unable to find password"); //$NON-NLS-1$
 		}
 
-		try {
-			byte[] utfbytes = password.getBytes();
-			return new String(utfbytes, "UTF8"); //$NON-NLS-1$
-		} catch (UnsupportedEncodingException e) {
-			return ""; //$NON-NLS-1$
-		}
+		byte[] utfbytes = password.getBytes();
+		return new String(utfbytes, StandardCharsets.UTF_8);
 	}
 
 	private void saveMasterPassword(String password) throws SecurityException {
@@ -171,15 +167,10 @@
 		String passwordUTF8 = password;
 		PointerByReference gerror = new PointerByReference();
 
-		try {
-			byte[] utfbytes = password.getBytes();
-			passwordUTF8 = new String(utfbytes, "UTF8"); //$NON-NLS-1$
-		} catch (UnsupportedEncodingException e) {
-			// do nothing
-		}
+		byte[] utfbytes = password.getBytes();
+		passwordUTF8 = new String(utfbytes, StandardCharsets.UTF_8);
 
-		fLibSecret.secret_password_store_sync(fEquinoxSchema, SECRET_COLLECTION_DEFAULT,
-				"Equinox master password", //$NON-NLS-1$
+		fLibSecret.secret_password_store_sync(fEquinoxSchema, SECRET_COLLECTION_DEFAULT, "Equinox master password", //$NON-NLS-1$
 				passwordUTF8, Pointer.NULL, gerror, Pointer.NULL);
 
 		if (gerror.getValue() != Pointer.NULL) {
@@ -187,7 +178,7 @@
 			String message = error.message;
 			fLibGio.g_error_free(gerror.getValue());
 			throw new SecurityException(message);
-		}		
+		}
 	}
 
 	@Override